If you’re at all familiar with the Linux/Unix world, it’s safe to say you’ve probably heard of vim. The mode-based editor is famed for both its power and frustrating learning curve. Unlike most editors, which default to a mode where you can type text, vim defaults to a “command mode” where you can edit text through short commands bound to single keys on the keyboard. If you want to enter “insert mode” to type text, you need to press the
i key, and then the escape key to return to command mode when you’re done. The commands can even be chained together, so you can, for example, use
dw to delete the word the cursor is currently over. Or move the cursor three characters to the right with
The tricky part, besides learning and remembering the various commands is picking up the habit of not staying in insertion mode. The way you’re supposed to use vim is to enter that mode only for short bursts of typing. Then you exit back to command mode. This makes it more natural to use the fast cursor movement and text operation commands.
Why learn vim?
- It’s everywhere! Pretty much every *nix system has vim/vi preinstalled. (Even OS X!) So if you frequently connect to servers to edit config files, you’ll be able to do so much more effectively than if you use nano. (Strangely, though, Ubuntu doesn’t include vim by default. They have vi, but not vim. You can install it easily through apt, though.)
- It’s efficient. Once you get the hang of it, you’re not just operating a text editor, you’re flying a text editor. Watch someone take a large amount of tabular data and turn it into an HTML table with vim. Usually that would take awhile to do by hand in your average text editor. In vim? Thirty-two seconds.
- It’s stood the test of time. Vim has been around since 1993, and its more limited precursor, vi, dates back to 1978. Vim is an open source project that is still maintained to this day, and used by legions of programmers who depend on it, after all this time. It’s been here for a long time, and you can be sure it won’t be going anywhere. Which is more than I can say for Sublime Text, which, while I really like it as an editor, is maintained by one person. (The dev world is no stranger to projects grinding to a halt when the lead developer loses interest or passes away!)
- If you do use Sublime Text for larger projects, you can enable vintage mode to use the same vim commands in Sublime!
- For further reasons, see “Why, oh WHY, do those #?@! nutheads use vi?”
Learn vim! No, really, that’s it. Install vim, customize your .vimrc, and try using it for a week or two. Put some effort into learning it, give it a chance, and see how you like it. If you want to ease into it, you can use a graphical version like MacVim so you can still use the mouse or familiar keyboard shortcuts when you’re not feeling particularly adventurous.
Be sure to go through
vimtutor, which you should be able to launch by running
vimtutor at the command line. It walks you through the basics of using vim.