Vi, or "vee eye," is the standard screen editor on UNIX and is integrated with ex, a line editor. Vi is the visual mode of ex, and ex commands can be entered while using vi, making it a very powerful editor.
In this document, the string "[return]" means press the Return key and text in italics is what you actually type in on the system.
To invoke vi type
where "filename" is the name of an existing or new file. If "filename" is an existing file, the screen will show its contents, ready for editing. If "filename" does not already exist, the new file will initially appear on the screen with one tilde (~) on each line in the first column. The tilde represents a blank line in any file and is used primarily to fill up the terminal screen after the last line of the file, if there is any existing text. The last line on the screen is reserved for echoing certain commands as they are entered, or for showing informative messages given by vi.
Example ("%" is a command prompt):
"New_file" [New file]
Once you are in the editor, enter the command i to input text.
A copy of your file, or a buffer, is created when you edit a file using vi. This temporary workspace is where you will do your editing. The buffer is not saved until you do a write (:w, :wq, or <Shift>-zz) command. This copies the buffer onto disk and replaces the previous version of the file if one existed, or creates a file if not.
Editing in vi means alternating between the text input mode and the command mode.
Here are some basic vi commands:
Command -- Comments
<ESC> (ESCAPE) -- Ends text input and returns to command mode
i -- Input text to left of cursor
a -- Input text to right of cursor
o -- Input text below current line
O -- Input text above current line
h -- Move to immediate left
l or SPACE -- Move to immediate right
k -- Move up in same column
j -- Move down in same column
<Control>-d -- Scroll down half screen
<Control>-u -- Scroll up half screen
<Control>-f -- Scroll forward full screen
<Control>-b -- Scroll back full screen
0 -- Move to start of current line
$ -- Move to end of current line
nG -- Move to nth line of file
G -- Move to end of file
/string -- Move forward to first occurrence of string
x -- Delete current character
dd -- Delete current line
r character -- Replace current character by character
R -- Replace characters one by one (overwrite) - must <esc> to return to command mode
u -- Undo last deletion, input, or replacement