University of Delaware

The vi (visual) Editor: A Tipsheet


Index

Command mode and insert mode

Unlike most word processing software, the vi (visual) editor uses two different modes:

The commands you type in command mode

To add text to your file, use a vi command such as i. What you type in insert mode:

To return to command mode, press the ESCAPE key.

Back to Index

Creating and Editing a file

To insert new text into a new or existing file, follow these steps:
  1. At the UNIX prompt (%), type the command
       vi filename
    and then press the RETURN key. (Replace filename with the name of the file that you want to create or edit).

  2. To being inserting text in your file, type the command
       i
    Do not press the RETURN key.

    The "i" will not appear on the screen; it is a command that indicates you want to insert text.

Back to Index

Saving a file

When you are done adding or editing text in the file and you want to save the file, press the ESCAPE key. You will return to command mode. To save your file, type
   :wq
You should see the UNIX prompt (%) again.

Back to Index

Command mode commands

File saving and Loading

:e filenameedit new file filename
:r filenameread in contents of filename
:qquit editing
:q! quit editing and discard changes
:wqwrite file and quit
:w filenamewrite to the file named filename
:wwrite to the file already named
:w! filenameoverwrite the file filename

Back to Index

Insert mode commands (text entry)

aappend text, after the cursor position
Aappend text to end of the line
iinsert text, before the cursor position
Iinsert text at the beginning of the line
oopen new line below cursor, enter insert mode
Oopen new line above cursor, enter insert mode
Renter overstrike mode, press the ESCAPE key to exit

Press the ESCAPE key to exit insert mode.

Back to Index

Search commands

/textsearch forward for first occurrence of text
?textsearch backward for first occurrence of text

Back to Index

Cursor control commands

bgo to beginning of word
ego to end of word
Ggo to the last line of the file
##Ggo to the ##th line of the file
hmove left one character
j or RETURNmove down one line
kmove up one line
l or SPACEBARmove right one character
{move to the previous paragraph
}move to the next paragraph
$move to the end of the line
^move ot the beginning of the line

Back to Index

Basic text manipulation commands

dddelete one line (place in general buffer)
djdelete current line and one below
d}delete up to the end of the paragraph
Ddelete the rest of the line
Jjoin two lines
rreplace character on which the cursor rests
senter insert mode to substitute text for the character on which the cursor rests
##ssubstitute ## characters, enter insert mode
uundo the last change
xdelete one character
##xdelete ## characters

Back to Index

Advanced text manipulation commands

"apsame as p but from buffer "a"
"aPsame as P but from buffer "a"
"ayyank line into the buffer named "a"
cwdeletes word starting at the cursor, enter insert mode
pput contents of general buffer after current line
Pput contents of general buffer before current line
yyyank line into the general buffer
##yyyank ## lines into general buffer
##ylyank ## characters to left of cursor
>shift line right
<shift line left

Back to Index

Miscellaneous commands

CONTROL-Gprint information about file: name, current line number
:##go to the line numbered ##
:%s/pattern/text/substitute first occurrence of pattern on each line with text
:%s/pattern/text/gsubstitute every occurrence of pattern with text
:g/pattern/ddelete every line containing pattern
:10,50 yayank the contents of lines 10 through 50 and place in the general buffer
:%!sortexecute the UNIX command sort on every line, replace contents with output of command

Back to Index

IT Help Center
Questions or Comments
University of Delaware Home Page
Last updated: April 28, 2005
Copyright © 2005 University of Delaware