So now that we have all those beautiful editors, is still worth it to invest in learning Vim in 2019? The answer is yes and yes of cause.
In this article let me give some of the reasons why Vim is still the most productive editor for me.
1. Write And Change Faster
There are no questions here. Typing in Vim is the most efficient form of typing ever. This is why every IDE has a plugin for a “Vim mode”. You can have one Visual Code as well.
The whole idea of Vi/Vim is running around the modes switching between them you can type and change the code very fast because you don’t need a mouse. Instead, you navigate a file with the keys.
- to get to the top of the file
- move to the next word
- move to the next paragraph
f.in the line
- move to the next .
Navigation is one thing. But there are also keys you can type to change the code. And you can combine it with the navigation patterns.
- delete the entire line.
3dd- deletes 3 lines
- deletes the text till the dot. Note how we combine an action here (d) with a motion (f.)
- change in () brackets. Removes all the code within the brackets and lets you type something new
Admittedly, modes take some time to get used to. When you first start the Vim you start in NORMAL mode where you can’t type. Instead, you can run commands like the ones I just mentioned. If you want to type you need to go into the INSERT mode. You can do this by typing
i. And then after you finished press
Esc to return to NORMAL mode.
Still, this way of typing and navigating the code is so addictive that it’s really hard to go back from it to using the mouse.
2. Vim is fast and slim
Vim starts in several milliseconds. It doesn’t need to index the files or anything. It doesn’t freeze. It doesn’t take gigabytes of RAM. Actually Vim I’m writing in right now takes 5Mb.
And it is still capable of doing everything the most gigantic IDE does like syntax highlighting, auto-completion, refactoring capabilities, fuzzy searching, etc.
How does it do that? By delegating all this work to the other processes. This is very Unix-y where every process is aimed to do only one thing but do it well. And then the power comes when you combine those together.
3. Vim macros
One of the “aha” moments for every Vim starter is when he understands he can press “.” to repeat the last command.
Another “killer feature” is Vim macros. Since you change the text by running commands. You can actually record the sequence of the commands you use and run it again (or you can run it 100 times). It saves so much type when you need to change a big portion of text.
Just watch this video to get an idea of how powerful it is.
4. Syntax highlighting, linting, auto-completion, refactoring, fuzzy file search, navigate to the code
Yes. Vim can do all this. IMO, it does this even better than Visual Code. And at the same time, it remains very light and blazingly fast. I’ve already told you that it does that by delegating the work to other tools. The trick is that you have to configure it a little bit, and nothing is there for you out of the box.
Here’s an example. In order to fuzzy find a file you can make it use the FZF. You install the executable and the plugin for Vim, and it simply works.
If you use TypeScript, there is an executable called tsserver, which provides all the TypeScript magic for you like code suggestions, auto-completion, code navigation, compiling, etc (actually Visual Code also uses it). So you can install a couple of plugins and use it as well.
And now I press
gq to format the file. Well, in reality, I have this formatting on save option. But you get the idea.
The power of Vim comes from the fact that you can combine all those beautiful tools you have installed on your system to build the best IDE you can imagine (and the most personalized for your needs).
So if you are a Front-end developer probably the Visual Code is a very good option for you now. What if you are a Java developer, would that still be an option? Probably not. For Java, most likely you would need something like IntelliJ IDEA. What about Python?
So if you have to switch between multiple languages, you’d probably need to switch between different IDEs as well. I’m a full-stack developer so this problem is very real to me.
Where to next?
So hopefully I could persuade you at least that Vim is worth looking into. The amount of time invested in learning it pays off tremendously. Here are some links for you if you’d like to dive deeper from this very blog
- Starting With Vim
- Setting Up Vim For TypeScript
- 5 must-have Vim plugins in 2018
- 5 Awesome Vim Plugins You May Never Have Heard About
Also since I’m working on a “Vim from Scratch” video course I suggest you subscribe to my mailing list to get notified!