Vi Text Editor

Vi is a screen version of the ex editor, and many of the same commands apply. To enter vi type:
vi filename
If no file name is given, an empty file will be created.

Modes

There are two basic modes in vi: "command mode" (what it starts at), and "edit mode" (insert mode). "Command mode" understands specific commands, while "edit mode" accepts only text to be inserted into the file. Press the ESC key to toggle between them...

Moving the Cursor

To move to cursor, use the following commands (the editor must be in "command mode"):
 
h One space to the left (left arrow)
k One line up (up arrow) 
j One line down (down arrow)
l One space to the right (right arrow)
^ Beginning of current line
$ End of current line

Text

To insert text, go into "edit mode" by typing a, i, o or O (vi is case-sensitive). Anything typed is entered as text into the file. "Esc" returns you to the "command mode":
 
a Appends text to the right of the cursor
i Appends text to the left of the cursor
o Opens a new line below the current line
O Opens a new line above the current line
Other commands can be used to modify text that has been typed. They may only be used in "command mode" (type "Esc" to go from "edit mode" to "command mode"):
 
x Deletes character at cursor position
dd Deletes current line
U Restores current line

Quitting

To quit, use one of the following key sequences (these will only work in "command mode"):
 
:w [filename] Writes changes to [filename] 
:q Quits vi after above sequence is given
:q! Quits without any changes to the file being edited
:wq or <shift> ZZ Writes file and quits
Note: All but ZZ require carriage returns to execute the function.

Math Sciences Computing Center, University of Washington
Please email consult@ms.washington.edu if you have comments or questions