Systems & Software Solutions
December 12, 1998
This manual gives a brief overview of the more common vi commands. It is a companion to the Vi Introductory Guide.
Copyright 1988, 1989, 1991, 1993, 1994, & 1998 by Susan Liebeskind (Atlanta, GA) and Miles O'Neal (Austin, TX). All rights reserved. Permission is hereby granted to redistribute this in either source or formatted form, so long as this copyright & the author's names are included, unmodified in content, and so long as no charge beyond reasonable cost of reproduction is charged. Notwithstanding, inclusion in any other work or collection which is sold, rented, or otherwise charged for, is prohibited without express consent of the authors.
Rev. 1.1 Jan 9, 1990 meo
Rev. 1.2 Jan 1, 1992 meo
Rev. 1.3 Mar 22, 1994 meo
Rev. 1.4 Aug 3, 1998 meo
Rev. 1.5 Dec 12, 1998 meo
2. Command Mode vs Text Mode
3. Cursor Motion
4. Editing Commands
4.1. Delete Commands
4.2. Replace and Change Commands
4.3. Search Commands
4.4. Undo Command
4.5. Saving & Exiting Commands
4.6. Search & Replace Command
4.7. Yank (Copy) Commands
4.8. Put (Paste) Commands
4.9. Miscellaneous Commands
5. Miscellaneous Notes
Vi is actually a very powerful editor, and is organized in a logical fashion. It is different from other editors or word processors, which may make learning it just a little bit tricky for some people. If you approach it analytically and fearlessly, you should become proficient with it in a short period of time.
I highly recommend experimentation. For obvious reasons you should restrict early experimentation to test files.
Some non-display character keys and other keys have special functions. These keys will be shown by placing their name (such as RETURN) in square brackets, like this: [RETURN].
Unlike most non UNIX1 products, vi is case-sensitive. Be careful with the [CAPS LOCK] key (except in input mode). If things are acting strange, make sure [CAPS LOCK] is off. If you are unsure about this, a good test is to press the `j' key; if it moves the cursor down a line, [CAPS LOCK] is not on; if it joins the next line to the current line, [CAPS LOCK] is on.
Not all of the commands mentioned here are covered in the VI Introductory Guide. There are also far more commands available in vi than are covered here - for further information check your system documentation or get one of the books available on vi.
|Key||Command Mode||Text Mode|
|Arrow Keys||cursor movement||N/A|
|[CTRL]||used with other keys for extra commands||insert control characters in text|
|[ENTER] or [RETURN]||down 1 line||normal function|
|[ESC]||N/A||leave text mode|
|Space Bar||move right 1 character||normal function|
When a command is shown as a combination of the `^' (caret) and another character, as in ^V, this means press the [CTRL] key first, and hold it down while you press and release the other key.
In command mode nearly every key on the keyboard performs some command or modifies the next command. Some of these commands may be difficult to recover from, so be careful in command mode to enter only the commands you wish to enter.
The [RETURN] key is not needed in command mode except with commands that begin with a `:' (colon) and with the search comands.
|Mode Change Commands|
|a||append text after cursor|
|i||insert text before cursor|
|o||open new line after current line & add text|
|O||open new line before current line & add text|
|[ESC]||leave text mode|
|Cursor Motion Commands|
|h||move back 1 character|
|l||move forward 1 character|
|j||move down 1 line|
|k||move up 1 line|
|b||back to beginning of word|
|e||forward to end of word|
|w||forward to beginning of next word|
|^||go to first displayable character of line|
|0||go to beginning of line|
|$||go to end of line|
|<CTRL>F||forward 1 screen|
|<CTRL>B||backward 1 screen|
|<CTRL>D||down (forward) 1/2 screen|
|<CTRL>U||up (backward) 1/2 screen|
|dw||delete rest of word|
|d$||delete rest of line|
|D||delete rest of line|
The change and substitute commands, the editor puts you into insert mode until you press [ESC]. The replace command replaces 1 (or more) characters with the next character you type.
|cw||change rest of word|
|c$||change rest of line|
|C||change rest of line|
|Ns||substitute text for N characters|
|/text||search forward for text|
|?text||search backward for text|
|n||search in same direction for next occurance of last-searched-for text|
|N||search in other direction for next occurance of last-searched-for text|
Some vi clones, such as vim, allow multiple undo's. These usually offer a way to set the undo level to the standard vi mode. See your editor's man page or reference manual for details.
|u||undo last command (BE CAREFUL WITH THIS)|
|Saving & Exiting Commands|
|:w||write (save) the file|
|:w NAME||write the file and name it NAME|
|:w! NAME||rewrite the file named NAME|
|:wq||write the file and quit the editor|
|:q||quit the editor|
|:q!||quit the editor (abandoning any changes)|
:%s/text1/text2/g[RETURN]which replaces all occurances of text1 with text2.
|yw||yank rest of word|
|y$||yank rest of line|
|yy||yank entire line|
|Y||yank entire line|
|p||put yanked/deleted text before cursor|
|P||put yanked/deleted text after cursor|
If you yanked/deleted a whole line (or group of lines), p and P paste the text before or after the current line, respectively; otherwise, they paste the text before or after the cursor, respectively, on the current line.
|.||repeat last command (BE CAREFUL WITH THIS)|
|J||join next line to end of this line|
The period, or dot, command repeats most commands, but not quite all. It should work with all of the commands listed in this document; if you aren't sure of what you're doing, save your work before you try something.
3ddwould delete 3 lines, starting with the current one.
Vi will not let you delete more lines than are in the file, so the above example would not work on the last line; vi would beep at you instead.
Copyright 1988, 1989, 1991, 1993, 1994, & 1998 Miles O'Neal, Austin, TX, and Susan Liebeskind, Atlanta, GA. All rights reserved. Miles O'Neal <roadkills.r.us@XYZZY.gmail.com> [remove the "XYZZY." to make things work!] c/o RNN / 1705 Oak Forest Dr / Round Rock, TX / 78681-1514