I use vim.
Vim is a 20-year-old text editor, based on the 35-year-old “vi” editor (pronounced vee-eye, not vie). vi and emacs are both part of an editor holy war that has been going on for decades. I discovered this holy war years ago, mentioned on some website or another, and started to research. I tried both editors briefly, and then decided to take vim’s side of the holy war. At the time, this pick was kind of arbitrary – I really didn’t know enough about the two editors to make a truly educated decision. I think I saw vim as the underdog in the war, and as the more interesting of the two editors, with it’s strange idea of separate modes for text entry and for commands.
I’ve never looked back. When I first picked up vim, it was mainly so I’d have bragging rights that I could program in a crazy-old terminal editor. However, a few years later and I do everything I can to work in vim as exclusively as possible, whether for school, work, or personal projects.
People often comment on my choice. Why am I not using the feature-rich IDEs available for the language in which I’m coding? Why am I using such an old, out-dated piece of software? (This question just shows ignorance – the latest version of vim, 7.3, was released Aug 2010) What’s so great about vim?
That’s what this article is about. Just as John Beltran de Heredia did in his article, I’m going to try to break some of the misconceptions surrounding vi/vim, and show you why vim is king. For those who already are convinced and are looking for some vim resources, jump to the resources section at the bottom.
Normal vs. Insert Modes
The first time you try vi/vim without any real introduction to it, the result is almost always the same. First, there’s the disgust that you feel when you find out that to even enter any text, you have to hit ‘i’ to enter insert mode. The normal and insert modes of vim are probably its most misunderstood feature, and what makes vim so powerful. But misunderstood, the result usually is that you get into insert mode, use the arrow keys to navigate around, and do everything you can to stay in insert mode. That’s how we’ve been trained – if we enter a letter, that letter should appear on the screen. So you stay in insert mode, dink around for a few minutes, then throw your arms in the air, yell “What’s the point??? This is so stupid.”, and then never come back.
It turns out that this is not the way to use vim at all. The key thing to remember with vim is that you stay in normal mode almost all the time, entering insert mode for short bursts of typing text, only to return immediately to normal mode. John Beltran hits the concept on the head in the article I linked to earlier:
Thus, the remembering-the-mode problem just doesn’t exist: you don’t answer the phone in insert mode to get back to vi and not remember where you were. If you are typing text and the phone rings, you exit insert mode and then answer the phone. Or you press ‘’ when you come back. But you never think about insert mode as a mode where you stay.
Let me explain the philosophy behind this.
Commands in vi/vim are meant to be combined - ’d’ means delete, ’e’ means ‘move to end of word’, then ‘de’ is a complete command that deletes to the end of the current word (something like Ctrl-Shift-Right, Left, Del in most regular editors).
When you compare ‘de’ to the ‘Ctrl-Shift-Right, Left, Del’ in most regular editors, you start to see the beauty of the system.
Interestingly enough, inserts are considered commands as well. If you type ‘i’ to begin inserting text before the current character, type a word or two, and then hit ‘Esc’, that entire operation is a command. This is important to remember because of another key piece of functionality: the ‘.’ key. When in normal mode, the ‘.’ key will repeat the last complete, combined editing command you executed. This could be the ‘de’ command we mentioned earlier, or it could involve inserts. For example, if you typed ‘iHello’, then it would insert the word “Hello” before the starting location. Then, if typed a ‘.’, it would repeat that operation.
The interesting thing is that you can also add a number argument before almost any command (whether movement command or editing command), and that command will be repeated that many times. All these concepts can be combined to result in incredibly flexible editing power. Jon Beltran does a good job of a more in-depth exploration of the power of vim, so I’ll link you over to his article again if you want to learn more.
Vim is generally known for it’s very steep learning curve. I won’t deny, the learning curve is definitely there. However, I will say that if you can stick with it, you’ll never regret it. Vim key bindings allow you to basically ditch your mouse, as well as carpal-tunnel inducing crazy key bindings for basic operations. Everything is at your fingertips, and it’s so powerful! You can also find vim emulation plugins for many modern IDEs, such as Eclipse, Visual Studio, etc. Another interesting fact is that the default shortcut keys in Gmail are vim-inspired!
If you really want to try to learn vim, head over to Jon Beltran’s site and get his vi/vim graphical cheat sheet. I found this invaluable as I learned vim. You’ll also find many good books on vim. Just follow the reviews on Amazon or a similar site, and you’ll find them.
Once you have the basics down, you can start exploring ways to extend and customize vim. You’d be amazed to find out how truly customizable it is. In fact, if you’re interested, check out my dotfiles! This is a collection of my various configuration files, including my vim configuration files. I’ve tried to comment everything thoroughly enough that you’ll be able to follow what purpose each command serves, but feel free to use the issue tracker to ask questions! You can even fork the repository (it’s on Github), and modify to suit your needs! It’s designed to be cross-platform (it requires one small change in the .vimrc to define the platform), so it should be pretty easy to incorporate.
I’d love to add to this list of resources, so if you have a good one, leave a comment!