"Practical Vim: Edit Text at the Speed of Thought" by Drew Neil. He also has a bunch of helpful short video tutorials over at http://vimcasts.org. |
I could barely stop myself from diving into it immediately. As soon as my son fell asleep, I started to devour the pages. If someone had told me ten years ago that I would love reading a guidebook for a command-line text editor, I probably wouldn't have believed it. But, I have to admit, I've become a great admirer of vim.
So, what's the story behind this humble piece of software? The original vi was developed by a guy named Bill Joy for machines running Unix, back in 1976. Vi continued to evolve over the years until another guy, this one named Brian Molenaar, released vim (Vi IMproved) in 1991. Vim is, in simplified terms, an extended version of vi. Today, vim is in version 7.4, but still no more than a few megabytes in size. It's available for numerous operating systems, including Mac OS X, Windows and Linux. While vim continues to evolve, it still has that austere design:
So, what's so great about vim? There's of course the aesthetic dimension: I can decide on a color scheme and a font, and then I won't have to bother with a single menu of any sort. The interface is extremely minimalistic, which I love. Then there's the economic dimension: vim is completely free. Unlike the apps you see on you Android phone, that doesn't mean that you'll be pestered by ads or have to surrender your e-mail address. It's free and open-source, so just download it and enjoy, no strings attached. In addition, it's small and doesn't demand much in terms of processor power, RAM or disk space, so you can easily use it on an old computer. I could probably get it up and running on a 486 using a minimal Linux installation. Most importantly, there's the work-flow dimension: vim is a very sophisticated tool for editing text. I'm not going to say it's easy to learn, but it can be incredibly rewarding in ways that no word processor can rival.
The screen you see if you open vim without specifying a file. |
I'm a political scientist, not a programmer. I work with large chunks of text, and I spend a lot of time tinkering with them: deleting, modifying, adding, etc. Vim takes this to perfection, and you never have to touch the mouse. You don't even have to move your hands from their original resting place on the keyboard, every command you can possibly need is only a few letters away. The most fundamental aspect of vim that enables this is the modal editing. While most word processors and graphical text editors are always in the same mode, using vim you will constantly switch between at least two, and sometimes three different modes. The first mode is "normal" mode. It enables you to, for example, navigate the text and delete parts of it. But in order to type anything, you have to enter "insert" mode, which makes the keys respond differently. The lettered keys used for commands in normal mode will then correspond to the actual letters printed on them instead. Finally, there's "visual" mode, which enables you to select parts of the text. There are a few other modes, but these three are the most important ones.
Instead of clicking and highlighting in the text, you move the cursor around. Either one character/line at a time by using the h, j, k and l keys (you can also use the arrow keys, but the point in using hjkl is that you don't have to move your hands away from their starting position). However, moving the cursor inside long paragraphs in files that cover the equivalent of dozens of printed pages isn't very effective, but vim has a lot of other ways of moving around. Using the w and b keys, you can skip back or forward one word at a time. Using "(" and ")" you can skip one sentence at a time and using "{" and "}" you can move an entire paragraph at a time. Or, you can type the letter f, followed by a character, to skip forward directly to that character on the same line. Or, type / followed by a word to skip ahead to that word. Replace the / with a "?" to skip backward. Then I can type "n" to skip to the next matching word. This is just scratching on the surface, there are commands for deleting, copying or changing a specified number of words, lines, sentences, you name it. Commands for moving around within the text can be combined with commands for editing it in a myriad of ways, creating almost infinite flexibility. Then there's the arguably most clever command of them all, press "." to repeat the previous change. If that's not enough, there are plenty of plugins you can add. Or create your own macros. In vim, creating macros is as easy as typing two letters, then the commands you want in your macro, then another letter to stop recording the macro. You can then invoke the macro by pressing two different keys.
For me, it's like playing the piano. Not that I can play the piano, but at least that's how I picture it in my head. When I get a nice flow going while working at the command-line, my hands are flying across the keyboard, every thought is almost instantly translated into commands and text, the resulting feedback comes instantaneously. I'm not that good at vim yet, but I know that in time, being that fast is a realistic goal. Like playing the piano, it's all about practice. Fortunately, you can practice while working.
Vim is optimized, honed and perfected for touch typists. If you can't touch type, then vim is probably not going to save you any time (it could still make for a nice-looking alternative for people on a budget though). Learning vim, just like the command-line in general, is like learning a language. There are no visual clues to provide immediate help. You have to go through the process of learning the words, or in this case, commands. At first, you'll have to think about each command, just like you have to build a sentence in your head when you're struggling to speak an unfamiliar language. With practice, the commands come as naturally as words when you speak. Thoughts enter directly onto the screen, limited only by the speed of fingers. Once you get into that flow, when the commands have become embedded in your subconscious, the feeling of doing something as mundane as editing text can be as sweet as playing music.