The AVIDD-B Cluster
Using the vi Editor
Entering vi
Before entering vi, make sure that your environment variable TERM is set correctly. When vi starts up it looks at TERM to see what kind of terminal you are using. It will then load the proper terminal control information from the file /etc/termcap (terminal capabilities file).For Bourne (sh) and Korn (ksh) shell users:
$ TERM=vt100
$ export TERM
$ vi filename
For C Shell (csh) users:
% setenv TERM vt100
% vi filename
The Most Important Commands of All
u - undo (undoes the previous command) U - undo all changes to the current line Ctrl/l - clears and redraws the screen :q! - exit VI and DO NOT save the changes :ZZ - exit VI and SAVE the changes
Scrolling
Ctrl/u - scroll Up one half screen Ctrl/d - scroll Down one half screen Ctrl/f - scroll Forward one full screen Ctrl/b - scroll Backward one full screen
Moving the Cursor
b - move to Beginning of previous word
e - move to End of next word
w - move to next Word
( - move backward to beginning of sentence
) - move forward to beginning of sentence
{ - move to beginning of paragraph
} - move to end of paragraph
$ - move to first nonspace character on line
h - move cursor to left
j - move cursor down to next line
k - move cursor up to previous line
l - move cursor to the right
Input Mode
The ESC key terminates input mode and returns you to command mode. The following commands will put you in input mode:a - append text after the cursor i - insert text in front of cursor o - open a new line below the current line s - substitute character A - append text at the end of the line I - insert text at the beginning of the line O - open a new line above the current line R - replace text beginning at the cursor S - substitute entire line
Deleting Text
Deleted text is placed into the undo buffer. If you make a mistake when deleting text you can undo the delete by typing 'u' to undo the last delete or 'U' to undo all changes made to the current line. You can also insert the deleted text in another part of the file by using the 'p' or 'P' command. More about that later.X - delete character to left of the cursor x - delete character under the cursor dd - delete entire line dw - delete word d( - delete to beginning of sentence d) - delete to end of sentence d^ - delete to beginning of line d$ - delete to end of line D - delete to end of line
Examples:
5dd - delete the next 5 lines 10X - delete 10 characters to the left of the cursor 3dw - delete the next 3 words
Yanking Text
When you yank text you are simply copying text from the file into the undo buffer. The yanked text can then be inserted in another part of the file by using the 'p' for 'P' command. The 'p' command will insert the contents of the undo buffer after/below the cursor. The 'P' command will insert the contents of the undo buffer before/above the cursor.yy - yank entire line yw - yank word y( - yank to beginning of sentence y) - yank to end of sentence y^ - yank to beginning of line y$ - yank to end of line Y - yank to end of line
Examples:
5yy - yank the next 5 lines 3yw - yank the next 3 words
Changing Text
The change command is used to modify existing text in a file. After you type the change command, vi will mark the end of the selected region of text with a dollar sign ($) and go into input mode. After you have finished typing in the text press the ESC key to exit input mode.cc - change entire line cw - change word c( - change to beginning of sentence c) - change to end of sentence c^ - change to beginning of line c$ - change to end of line C - change to end of line r - replace the character under the cursor R - replace the text starting at the cursor
Examples:
5cc - change the next 5 lines 3cw - change the next 3 words
Character String Searching
/ - search forward in file for string ? - search backward in file for string n - locate next occurrence of string N - locate next occurrence in opposite direction
A Few of the Special Characters in Search Strings
^ - match string starting at beginning of line $ - match string starting at end of line . - match any character
Examples:
/text/ - searches forward for 'text' ?text? - searches backward for 'text' /^buddy/ - searches forward for 'buddy' at beginning of line /csh$/ - searches forward for 'csh' at end of line
Miscellaneous Commands
:r - This command allows you to read a file into the one that you are editing. Simply place the cursor on the line above the spot you want to read the file in and enter :r file_name.
:r!unixcommand - This will execute the specified UNIX command and insert the command's output into the edit file after the current line.
Ctrl/g - This command will display a status line at the bottom of the screen to show you where you are in the file.
For more information about vi, one book available is Learning the vi Editor by Linda Lamb (O'Reilly and Associates, Inc., 1992). $21.95.




