In his last class, he taught you the basics of vi, the powerful *NIX text editor. Now Elias Flootburger returns in this hilarious sequel to theoriginal "Vi 101" tutorial. This time, the good professor has his handsfull with abbreviations, key mappings, autocommands and vi's powerfulvisual mode...not to mention his own out-of-control ego!Note: Most of the material in this article covers vim, the enhanced version of vi that is preinstalled on most modern *NIXes.
Unlike some of its better-known brethren, vi comes with some powerful crash recovery features. For example, let's suppose you're editing a file named "cart.php3", and your system suddenly crashes because Joe in the other room mistook the server's power button for the microwave's on/off switch.
Hey, some people are just born stupid-after all, only a moron would keep the microwave next to the server!
Well, once you get the system back up, recovering your file is as simple as typing
vi -r cart.php3
For every file that you edit, vi creates a temporary swap
file by the same name and the file extension .swp in the same directory. When you add the -r parameter to the file name, vi will attempt to "recover" the file by reading the temporary backup and combining it with bits of the original file to get you back to where you were before the crash.
The temporary swap file is usually updated every four seconds or every 200 characters - although you can change this with the "updatetime" and "updatecount" commands.
Once you've confirmed that the restored version of the file is acceptable, you should delete the swap file to avoid error messages.
In addition to swap files, another very important file is the vi configuration file, usually found lurking in your home directory under the name ~/.vimrc . This configuration file is read every time you start the editor, and the commands and options in it executed automatically.
All the "colon" commands you've learnt thus far can be placed in the configuration file for automatic execution. There's one simple rule of thumb - if you execute the command while the editor is running, you usually need to precede it with a colon [as in the examples above]; however, the same command, when placed in the configuration file, will *not* be preceded by a colon. So, for example, though I might type
:abbreviate god Professor Elias Flootburger The Third
in the editor, my configuration file would only contain
abbreviate god Professor Elias Flootburger The Third
without the initial colon [:]
A simple way to create
your .vimrc configuration file is to set the editor up the way you want, and then execute the command