How to edit text with Vim
Old school geeks use a *nix text editor
By Ian Harac | PC World | Published: 15:30, 15 July 2010
Free text editor Vim is a Windows (and many other platform) implementation of the classic *nix text editor, vi. "Vim" is short for "Vi, Improved", and while it has features vi lacked (such as scripting, file merge, and a GUI shell), the heart of it is vi.
Do not confuse "text editor" with "word processor." Vim is intended primarily for editing code, especially batch files and scripts, though it can certainly be used for other things. Furthermore, Vim is modal, which is a concept that might be odd to many modern (i.e, post 1980) users. In insert mode, when you hit a key, the key is entered into your document. In command mode, when you hit a key, an appropriate command is executed. Type "3dw" in insert mode, and you'll see those letters appear at your cursor. Type the same sequence in command mode, and you'll delete the next three words from your document. (Type 'u' to undo, of course!) You switch modes by hitting Escape. A small bar at the bottom of the screen will tell you what mode you're in.
This may sound like it's more trouble than it's worth, but once you're over the learning curve, Vim's power and speed is amazing. Because of the modality, the most common commands do not need to be "decorate" with ctrl- or alt- keys. Want to skip ahead a word? Hit 'w'. Want to skip ahead 7 words? Hit '7w'. Move to line 34? 34G. Top of file? gg. Last line in file? G. All of the major navigation and editing functions require only 2 or 3 keys, without the bizarre finger-straining exercises required by EMACS or prowling through menus. Vim for Windows maps most of the standard keys as well, so page up and page down work as expected, and if you want them to do something else, you can edit the keybindings file.
Related Articles on Techworld
Vim includes a basic GUI, and allows you to use the mouse to perform many commands, but if you limit yourself just to the mouse functionality, you might as well be using Notepad. If you primarily write formatted text, Vim is not the best tool for you (but if you need to write marked-up text, such as LaTEX, it can be very useful!), but if you edit a lot of batch files, PERL scripts, or the like, and especially if you regularly move between Windows and *nix environments, it's extremely powerful. Besides which, if you master Vim, your geek cred will definitely go up a few notches.