|
x
|
represents a single character
|
|
x |
control character: while holding down the
key, press x
|
|
text
|
one or more characters
|
|
n
|
represents a number
|
|
pat
|
text and pattern matching characters
|
|
|
Return key on your terminal
|
|
|
Escape key on your terminal
|
|
Entering and Leaving vi
Files |
|
vi filename(s)
|
edit a file or files
|
|
vi -r filename
|
retrieve saved version of file after system or editor crash
|
|
vi -x filename
|
edit encrypted file
|
|
vi -wn filename
|
set default window size to n (useful for dial-ups)
|
|
:wq
|
save (write) file and exit to system prompt
|
|
ZZ
|
save file and exit to system prompt
|
|
:q!
|
discard all changes and exit to system prompt
|
|
Basic Cursor Movement |
Use h, j,
k, and l to move the cursor--using
arrow keys may result in undesirable consequences |
|
h
|
move cursor left one character
|
|
j
|
move cursor down one line
|
|
k
|
move cursor up one line
|
|
l
|
move cursor right one character
|
(Any of the above commands preceded by n will move the
cursor n spaces or lines in the indicated direction.)
|
|
Inserting Text |
(If n precedes an insert character, n copies of
inserted text are added upon escape from insertion mode.)
|
|
a
|
begin insert at right of cursor
|
|
A
|
begin insert at end of line
|
|
i
|
begin insert at left of cursor
|
|
I
|
insert at beginning of line
|
|
o
|
open line below, ready for insertion
|
|
O
|
open line above, ready for insertion
|
|
S
|
replace text with blank line; begin insertion at beginning of that line
|
|
i
|
insert tab
|
|
v
|
insert non-printing character
|
|
|
erase character (invisible until over-typed or insert mode escaped)
|
|
|
terminate insert mode; also terminates unwanted commands
|
|
Deleting,
Retrieving, and Undoing |
|
dw
|
delete word
|
|
dd
|
delete line
|
|
yw
|
yank word into buffer
|
|
yy
|
yank line into buffer
|
|
x
|
delete character
|
|
D
|
delete characters from cursor to end of line
|
|
ndw
|
delete n words into buffer
|
|
ndd
|
delete n lines into buffer
|
|
nyw
|
yank n words into buffer
|
|
nyy
|
yank n lines into buffer
|
|
nx
|
delete n characters into buffer
|
|
p
|
put buffer contents after cursor
|
|
P
|
put buffer contents before cursor
|
|
u
|
undo last single change
|
|
U
|
restore current line
|
|
Changing, Replacing,
and Copying Text |
|
.
|
repeat last change
|
|
n.
|
repeat last change n times
|
|
cwtext |
mark end of a word with $ and change to text
(press to end) |
|
rx |
replace character under cursor with character x
|
|
nrx
|
replace n characters with character x
|
|
Rtext
|
write over existing text, ( to end)
|
|
J
|
join succeeding line to current cursor line
|
|
:s/pat1/pat2
|
on the current line, substitute the first occurence of pattern 1 with
pattern 2 |
|
:s/pat1/pat2/g
|
on the current line, substitute all occurences of pattern 1 with pattern 2
|
|
:&
|
;repeat the last :s request
|
|
:%s/pat1/pat2/g
|
substitute all occurences of pattern 1 with pattern 2 throughout the file
|
|
:.,$s/pat1/pat2/g
|
substitute all occurences of pattern 1 with pattern 2 from cursor to end
of file |
|
Moving Around in a
File |
|
g
|
ascertain line number of current line
|
|
G
|
go to end of file
|
|
nG |
go to line n
|
|
or + |
move cursor to beginning of next line
|
|
-
|
move to beginning of previous line
|
|
w
or nw |
move one word or n words to the right
|
|
b
or nb |
move one word or n words to the left
|
|
)
|
move to next sentence
|
|
(
|
move to previous sentence
|
|
}
|
move to next paragraph
|
|
{
|
move to previous paragraph
|
|
d
|
scroll down one-half screen
|
|
u
|
scroll up one-half screen
|
|
l
|
clear and redraw the screen
|
|
mx
|
mark cursor position with character x
|
|
`x
|
move to position marked with x
|
|
d`x
|
delete text from marked x to cursor
|
|
y`x
|
yank text from marked x to cursor
|
Note: If you precede the mark letter with '
(apostrophe) instead of ` (grave accent), the action will
apply to the entire line the mark is in, not the exact marked
location. |
|
File
Manipulation |
|
:rfile
|
read in a file beginning on the line below the current line
|
|
:w
|
save and remain in current file
|
|
:wq
|
save file and quit
|
|
:q
|
quit (leave unedited file)
|
|
:q!
|
quit and do not save changes
|
|
:!command
|
run single Unix command while editing (press
to return to file)
|
|
:sh
|
obtain temporary shell (D to return to
file being edited)
|
|
:n,mml
|
move lines numbered n through m after line l
|
|
:n,mtl
|
make a copy of lines numbered n through m and put
after line l |
|
:n,mwfile
|
write lines numbered n through m to file
|
|
:n,mw>>file
|
append lines numbered n through m to end of file
|
|
:'a,'bwfile
|
write block, marked with a and b, to file
|
|
Searching For Text |
|
/pat
|
go to pattern pat (forward in file from current cursor position)
|
|
?pat
|
go to pattern pat (backward in file from current cursor position)
|
|
n
|
repeat last search, looking in direction of initial search
|
|
N
|
repeat last search, looking in reverse direction of initial search
|
|
%
|
find matching ( ) or { } or
[ ] (can be used in combination with
/,?,n, or
N to search for matching brackets throughout file)
|
|
Setting Options |
Options are either toggled on and off, or given values. When
editing, set options for a file with the set command.
If you want options to be permanent in a particular directory, create a
.exrc file in that directory and set options in that
file: set option option option=n. (For
example, set ai sm sw=4.) If you want certain option
settings to apply throughout your Unix environment, edit your
.login file by entering setenv
EXINIT'set option option option=n' (for example,
setenv EXINIT'set ai sw wm=10').
|
The values in a .exrc file for a directory will
override the values of EXINIT in the .login file. If no
.exrc file exists, any option values set in the
.login are used. If some option values are set in the
.exrc file and others are set in the
.login file, values from both files are used.
|
|
:set all
|
displays all option settings on your terminal
|
|
:set
|
displays settings set by EXINIT, the
.exrc file, and any current changes
|
|
:set option
|
sets option
|
|
:set option=n
|
sets option and assigns it the value of n
|
|
:set nooption
|
unsets option
|
|
:set option?
|
displays setting of option on screen status line
|
|
Common Option
Selections |
(To see a complete list of options, enter :set all.)
|