This document is intended to be an introduction to the use of the VI editor. It is by no means complete.
The VI editor is available on the Unix computers at Niagara at the current writing. In the discussion below, we use the "$" as a generic representative of the operating system's prompt message. Some items will be underlined in order to stress what the user must type.
$ vi filenamewhere "filename" is the name of the file you wish to edit. VI may be entered in this way whether the file is old or new. Regardless, you enter VI in "command mode" (see the item on MODES, below).
Command Explanation i (insert) start at the position of the cursor a (after) start at the position following that of the cursor O (oh) start a new line above the position of the cursor o start a new line below the position of the cursor R (Replace) enter new text as strikeover for the current line -- however, any text you enter past the current end-of-line (i.e., by striking the return key) is entered as insertion, rather than replacement
jmoves the cursor down by one line; the command
15jmoves the cursor down by 15 lines. Except as noted, only the unmultiplied are given in the table below:
Command Explanation
j move down 1 line
k move up 1 line
return move to start of next line
h move left 1 character
backsp " " 1 "
l move right 1 character
space " " 1 "
w (word) move right 1 word
b (back) move left 1 word
e (end) move to end of current or next word
$ move to right end of current line
0 (zero) move to left end of current line
H move to top of current screen
L move to bottom of current screen
ctrl-u (up) move up half a screen (12 lines)
ctrl-d (down) move down half a screen
ctrl-f (forward) move forward 1 screen
ctrl-b (back) move back 1 screen
G go to end (last line) of file (unmultipliable --
see next command)
nG go to line n, e.g., 250G moves cursor to line 250
/string go (forward) to next occurrence of string. The
search wraps circularly past the end of the
file, if necessary, to search the earlier part
of the file for the string.
Example: /Niagara
moves the cursor forward to "Niagara"
?string go (backward) to previous occurrence of string.
The search wraps circularly past the start of
the file, if necessary, to search the later part
of the file for the string.
Example: ?University
moves the cursor backward to "University"
n (next) go the next (forward or backward) occurrence
of the string searched for by the last / or ?
command, respectively
Command Explanation
x delete current character
dw (delete word) delete from current character
through end of current "word" including
trailing blank(s)
dd delete current line
dG delete the part of the file starting with
the current line
r replace current character with next character
typed. For example, if the cursor is at the
"h" of the when the user types ri, "h" is
replaced by "i" so that the word becomes tie.
Command Explanation
:w (write) save to default filename without exiting VI
:w filename save to file named without exiting VI
:r filename (read) import named file, inserting it beginning at
line below current cursor location
ZZ save to default filename and exit VI to the
operating system
:q quit VI without saving (use :q! if changes you
don't wish to save have been made in the file)
Command Explanation
ctrl-g get line number of current line in file
J join next line to current line,
combining 2 lines into 1
u undo previous operation
Additional commands are discussed in this document.
Back to Boxer's Home Page