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.
The guys who created vi built in all kinds of creature comforts designed to reduce your interaction with the shell to a minimum. One of the coolest ideas they came up with was a "shell filter", which allows you to replace shell commands with their output without needing to leave the editor at all.
Try this - open up a blank document and type
Today's date is date
Now exit insert mode, position the cursor over the second
"date" in that line, and type
!!bash
The line should now read
Today's date is Tue May 2 15:54:13 IST 2000
or whatever the current date and time happens to be on your
system. Vi passes the word under the cursor to the interpreter specified by the user - the "bash" shell, in this case - as a command, and then replaces the word with the output of that command.
Despite these time-saving features, there are times when you'll want to execute a shell command directly. In vi, you can do this with
:! <shell-command>
So, if you needed a quick directory listing of the /home
directory, you could type
:! ls -l /home
and vi would pass the command to the shell, and display the
output to you.
Finally, vi also allows you to spawn a new shell with the
:shell
command. You can then execute shell commands and run other
programs - even a new instance of vi, although only the truly warped among you would find this entertaining.
Once you're done, simply log out of the spawned shell by typing
^-D
and you'll be returned to your original vi session.
This article copyright Melonfire 2000. All rights reserved.