Why Learn Vim In 2019?
Iāve been using Vim for more than 3 years now. This is an eternity in the web development world. So many things have changed but the most important and unbelievable thing happened is Visual Code, the slick IDE from Microsoft (!) that has become the most prevalent IDE for JavaScript. There are IDEs and editors out there are Sublime Text, GitHub Atom, and others.
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.
gg
- to get to the top of the filew
- move to the next word}
- move to the next paragraphf.
- move to the next . (dot character) in the line
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.
dd
- delete the entire line. 3dd - deletes 3 linesdf.
- deletes the text till the dot. Note how we combine an action here (d) with a motion (f.)ci(
- 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.
Or, I use prettier to format my JavaScript and React code. So in my Vim configuration I simply say, Iād like to use this executable to format those types of files:
autocmd FileType javascript setlocal formatprg=prettier
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).
5. Language-agnostic
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.
On the other hand, Vim can be set up to work perfectly well with any language. Currently, I use it on a daily basis for JavaScript, TypeScript, Ruby, Python, and occasionally ReasonML. I have set up and installed all the tools I need and now my Vim is perfectly suitable for each of it. Isnāt that awesome?
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