vitutor tutorial
vilearn tutorial
other VI manuals/tutorials
frequently asked questions
2-page PDF summary

Using the VI editor
(the very basics)

The VI editor is a screen-based text editor available on all Unix computers (and available for all other kinds of computers, sometimes as ``vim'' rather than ``vi''). Given that it takes some effort, why bother to learn VI? Because

If you will be using Unix/Linux computers, especially via ssh, save yourself headaches and learn the basics of VI now! This web page (and the 2-page PDF summary) are for reference; for a hands-on tutorial type the Unix command ``vitutor'' or ``vilearn'', or try the hyperlinks at the top of this page.

In the following, ^X denotes a control character. For example, ``^D'' means to hold down the Control key and press the ``d'' key. Also ``Rtn'' means to press the Return (or Enter) key, while ``Esc'' means to press the Escape key, located in the far upper left corner of the keyboard.

1. Starting: To edit a file named (say) ``mytext'' on a Unix computer, type the command ``vi mytext''. Note that you must type the command with lowercase letters.

2. Two Modes: Pay attention, this is the crucial feature of VI!   There are two modes, command and insert. When in insert mode, everything you type appears in the document at the place where the blinking cursor is.   When in command mode, keystrokes perform special functions rather than actually inserting text to the document. (This makes up for the lack of mouse, menus, etc.!)   You must know which keystroke will switch you from one mode to the other:

3. Getting out:  When you want to get out of the editor, switch to command mode (press Esc) if necessary, then

4. Moving Around:  When in command mode you can use the arrow keys to move the cursor up, down, left, right.  In addition, these keystrokes will move the cursor:
h         left one character
l         right one character
k         up one line
j         down one line
b         back one word
f         forward one word
{         up one paragraph
}         down one paragraph
$         to end of the line
^B      back one page
^F      forward one page
17G    to line #17
G         to the last line

5. Inserting Text: From command mode, these keystrokes switch you into insert mode with new text being inserted
i     just before the current cursor position
a   just after the current cursor position
o   into a new line below current cursor
I     at the beginning of the current line
A   at the end of the current line
O   into a new line above current cursor

6. Cutting, Copying, Pasting: From command mode, use these keystroke (or keystroke-combination) commands for the described cut/copy/paste function:

7. Searching for Text: Instead of using the ``Moving Around'' commands, above, you can go directly forward or backward to specified text using ``/'' and ``?''.  Examples:

8. Replacing Text: This amounts to combining two steps; deleting, then inserting text.

9. Miscellany: The commands on these two pages are just the start. Many more powerful commands exist in VI, especially those which invoke other Unix text-filtering commands (sort, fmt, uniq, cat, sed, awk, grep, etc.). More complete descriptions of all the possible commands are available on the web; see the list of VI manuals/tutorials maintained at The Vi Lovers Home Page or use a generic web search to search for ``vi tutorial'' or ``vim tutorial''.

Some useful or spectacular ``miscellaneous'' commands (not in categories 1-8 above):
typed command what it does
u undo the last change to the file (and type ``u'' again to re-do the change)
U undo all changes to the current line
^G show the current filename and status and line number
:set nu Rtn show all line numbers (``:set nonu'' gets rid of the numbers)
^L clear and redraw the screen
:%s/Joe/Bob/g Rtn change every ``Joe'' to ``Bob'' throughout the document
J join this line to the next line
5J join 5 lines
xp exchange two characters (actually the two commands x=delete and p=paste)
:w Rtn write (save) the current text, but don't quit VI
:12,17w filename Rtn write lines #12-17 of the current text to a (new) text file
:r filename Rtn read (and insert) contents of a text file
!]]sort -u | cat -n sort all lines from cursor downwards, deleting duplicates, and number the lines
:26,$s/\<[a-z]/\U&/g Rtn Capitalize the first letter of each word from line #26 through the end of the file