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.
According to Einstein, time is relative. According to Flootburger, time is money - especially when you're billing by the hour. And so, for all you smarmy consultants-to-be, here are some tips and tricks that should help you in bleeding the last cent from your eight-hour day.
First on the list: abbreviations. Vi allows you to define abbreviations for commonly-used words or phrases, and insert the complete word or phrase simply by typing its abbreviation. All this happens via the "abbreviate" command, which looks like this:
:abbreviate <abbreviation> <replacement-text>
or, for convenience,
:ab <abbreviation> <replacement-text>
From my own experience, I can tell you that this command is a
boon to all those of us blessed with a somewhat longer-than-usual name. In my case, for example, I often use this abbreviation:
:abbreviate god Professor Elias Flootburger The Third
Go on - try it out yourself. Each time you type the word
"god" in your document and follow it with either a space or a carriage return, vi will automatically replace it with the complete, unabridged version.
And once you get tired of seeing my name all over your document - how could you?! - you can remove the abbreviation with the
:unabbreviate god
or
:unab god
command.
To remove *all* abbreviations from memory,
the command to use is
:abclear
Abbreviations are particularly useful for inserting
frequently-used snippets of text - email addresses, telephone numbers and the like - into your documents. As a standard rule of thumb, if you find yourself typing the same piece of text more than five times in the same document, make it an abbreviation and use the money you save on RSI treatments to buy yourself a lifetime's worth of chocolate icecream - or simply donate it to the Flootburger Foundation For The Empowerment Of Semi-Retired University Professors. All donations are tax-deductible.
Vi also lets you enter symbols and accented characters, which cannot normally be entered with a regular keyboard. A digraphs table contains a list of different symbols, together with the key codes necessary to enter them; all you need to do is locate your symbol in the table, find the two characters that are mapped to create it, and enter them by typing
The first thing you need to do is look up the digraphs table to find out which combination of characters represents this symbol. You can access the digraphs table with the
:digraphs
command.
As you'll see, the digraphs table consists of
a series of columns - the first two columns contain the characters which, when combined, create the symbol in the third column. The fourth column contains the decimal representation of the symbol. Our copyright symbol, for example, is represented by the characters "A" and "~", and the decimal code 169.
Now, in order to enter this symbol into your document, move to the appropriate location and enter insert mode by typing