laitimes

Why I say Vim works better than VSCode

Author | Sean

Translated by | Wang Qiang

Planned by | Li Dongmei

Github was acquired by Microsoft and ushered in a fairly important feature update called Codespaces.

With it, you can write code directly in your repository without having to program it locally on your own computer. You can control a super fast server running VSCode from a browser to run code, provide services, and update code.

Vim used to be the most portable text editor because you can find it on almost any server machine and use it in the terminal via SSH.

Now, VSCode has some such features as well.

Not only can you run VSCode in Github, but Microsoft also offers a self-serviced version of VSCode called Open VSCode Server. You can use it to install VSCode on a single server and serve your app on any port you want. You can then access the server address in your browser and use VSCode in the same way as in Codespaces, but for free.

Microsoft is moving into the open source world

Microsoft's xterm .js (for VSCode's own terminals) was released as Microsoft's own proprietary open source project, which spawned a wide variety of browser-based terminals; you can now find one terminal on almost every server-hosted website.

The company has long been opposed to the open source model, but now they have embraced the open source world. In the world of web development, they are dominating. Microsoft has Ubuntu, Github, npmjs.com, and I rarely see developers who don't use VSCode.

When they started making VSCode so portable, even I started experimenting with Open VSCode myself. I wanted to see if I liked the feeling of writing code remotely, and if I could appreciate the benefits of its less refreshing GUI.

After running binaries on a cheap server that I rented £5 per month, it crashed almost immediately and I had to restart.

Vim is still better

Vim has an advantage over any GUI editor, and it's obvious for a few reasons. It's lightweight and fast, you can write code on the server via SSH, and everything can be done in the terminal. It is very versatile, portable and configurable.

You've probably heard of these reasons, so I'd like to talk about some personal reasons why I like it, as well as some areas where VSCode might be better at it.

Is it hard to use?

When I first mentioned that Vim was hard to use, the "Muggles" were turned away — I was kidding.

Actually, learning Vim is much easier than learning an instrument, but many people can learn to play an instrument; it's also much easier than learning to read and write, which is a very difficult thing, but almost everyone can do it.

It is certainly not a barrier to programmers from using it, which is difficult to use. Learning all kinds of difficult things is the foundation of our lives.

There are some benefits to learning something that is more difficult, but these benefits are not directly related to the fact that you are learning itself. You can gain some meta-skills along the way.

My son Yuri recently learned to ride a bike, which is difficult for him because riding a bike is not something you can learn little by little. Learning to ride a bike will have a moment similar to a leap of faith, where you have to try it in action and risk falling out of the car before you're mentally ready.

There's one more thing that makes cycling harder to learn: It's useless for you until you learn to ride a bike. So he used to like to pedal the scooter around, because the scooter is much easier to learn and the learning process is more interesting.

But Yuri hasn't touched his scooter since he learned to ride a bike because it's too slow and not much fun. Although he did not realize it, he actually learned some meta-experience in the process of learning to drive.

First, sometimes learning something requires a leap of faith, and you have to take a risk to take that step. Also, there are things that are useless until you learn them... And then all of a sudden they become so fascinating.

VSCode is like a scooter in a text editor, and Vim is a bike.

Vim is not asynchronous

Why is this an advantage? Well, that's why it's so fast. Vim only has about 7MB of space to occupy and will only do one thing at a time.

It doesn't scan your directory for function definitions, it doesn't traverse syntax trees to give you complex auto-complete suggestions, it doesn't compute the context of your cursor and make requests to the Document API, it doesn't git blame every line of code, it doesn't automatically download the syntax for every file.

But Vim can do all of these things... Just let it do it.

It only does what you let it do

Some people like the auto function because everyone wants their life to be easier. Or maybe you don't have the time or energy to deal with these little things.

I guess it depends on how you feel about your level of work, whether you have the energy to use terminal commands to lint your files, or read:help to figure out how to configure your .vimrc files (I never used Help when I started using Vim, internet resources were definitely your best friend in the beginning).

But to be honest, a lot of people I know waste their time in less fun ways, like rambling aimlessly on Facebook or re-watching a few episodes of Friends on Netflix.

Sometimes I want to do something more interactive instead of writing code from start to finish. If I'm tired after work or on weekends, I used to play music or computer games; now I'll fix something at home or tinker with Vim.

I'll think about some of the little features I can write in Vimscript, or integrate a useful command-line tool, or even just read something I've never seen before: help... In short, it is enough to let me have something to do, not a task I have to complete, but it is not a complete waste of time.

Vim makes code write like a game

When I learned more about Vim, I stopped playing computer games because it was controlled like a game. Vim has a modular structure that allows you to operate using a combination of various commands. It's a lot like the way you do combos in a fighting game.

Most commands have two, three, or four parts. A version of the three-part structure is this: operator - text object - motion.

Operators include delete, change, visual select, and replace, one at a time.

The text object is either inside or around.

There are many kinds of actions, which we'll discuss in detail later, and now we can think of actions as a kind of target of commands. For example, I can press dib, which means delete inside a block.

where the operator is delete, the text object is inside, and the action is block. This makes it possible to delete everything within a (parenthetical) block.

The number of available combinations is large:

di' – deletes the contents of the "single quotation mark" inside.

da" – Delete the content around around the "double quotation marks".

dit - deletes the content within the html tag .dll.

ci[- Change] in square brackets.

As I said earlier, there are many action commands to choose from, and they all behave differently depending on whether you're using them in a three-part combination (as described above) or in a two-part combination (in which case you remove the text object and let the command run backwards from the cursor position).

These commands allow you to quickly and easily change the contents of a function, the contents of a string, or the contents of an if block. Once you learn these commands, you'll want to use them everywhere.

Other text editors can feel cumbersome and cumbersome, and you'll install Vim Mode in every environment you can find.

More about actions

Actions are the type of key commands you use the most in Vim because they can be used to move the cursor alone. Some actions can be used individually, while others can only function when used as part of a combination.

For example, the w(forword) key will skip the cursor forward one word at a time, but the single quote is not a separate action, its effect is something else entirely.

Some actions change into different types, depending on whether they are used in combination or alone. For example, in the three-paragraph combination above, the b key means block, but when you use it alone, it means back, and moves the cursor back one word at a time.

Vim's commands are context-aware and modular. Different keys mean different actions, depending on when you use them and where the cursor is located.

It's a lot like a language, and you can think of these commands as a sentence: delete inside these 'single quotes'.

https://sean-warman.medium.com/why-vim-is-better-than-vscode-d09e2355eb37

Read on