Overviewvi is an editor that is on every UNIX box in the world. It can be obtained for Windows environments. I do all of my editing using vi, using it for both documentation and coding. If you are going to work in an internetworked environment, you need to learn to edit text (ASCII) files rather than relying on an editor which creates binary files. This website was written using vi and standard UNIX shell commands. The ability of vi to use regular expressions allows great swathes of data to be modified using just a few keystrokes. One great thing about vi is that all the editing keys can be found within the alpha-numeric key set. What this means is that you are not constantly looking for such remote keys as F3, CTRL, End, etc... Here are some examples:
Over the course of days, months, and years, one saves a lot of typing, a lot of looking, and a lot of finger stretching. Another neat aspect of vi is that the entire UNIX command set is pretty much built into the editor, as well as vice-versa, the vi command set is available from the UNIX command line. Brilliance.
Edit ModeWhen you first enter vi, you are in command mode. To go into edit mode, where one can actually type characters, enter one of the following:
To go back into command mode, at any time, type an <ESC>.
Command Mode
Running vi commands from the command lineMany of the commands listed above will work from the command line. To enable set your SHELL environment variable to ksh and your EDITOR environment variable to vi. Run something like the following on the command line or in your $HOME/.profile file: SHELL=ksh EDITOR=vi export SHELL EDITORor ksh set -o vi Once the environment is set, to get into vi editing mode, just type <ESC> and run whatever vi command you wish. For example, to pull up your last command without retyping it, run: <ESC> k To scroll through a list of your previously run commands run <ESC> kkkkk... To search for a previously run command use: <ESC> /command To search for string in a collection of files, and automatically edit all files containing string, run: vi `grep string *.html | cut -d: -f1 | sort | uniq` Once in the editor, you can do the things like the following:
Text ManipulationWhat follows are examples of how these commands can be used on the text in your file. The last line of each example is the command you type in to affect the lines above in the text body.
|