Vi Reference Card

ADVERTISEMENT

Vi Reference Card
Yanking text
Regular expressions
Like deletion, almost all yank commands are performed by
any single character except newline
. (dot)
typing y followed by a
. For example y$ yanks to
zero or more repeats
*
Modes
the end of line. Two other yank commands are:
any character in set
[...]
Vi has two modes: insertion mode, and command mode.
any character not in set
[^ ...]
line
The editor begins in command mode, where cursor move-
yy
beginning, end of line
^ , $
line
:y
ment and text deletion and pasting occur. Insertion mode
beginning, end of word
< , >
begins upon entering an insertion or change command.
grouping
(
)
Changing text
[ESC] returns the editor to command mode (where you can
contents of n th grouping
n
quit, for example by typing :q!). Most commands execute
The change command is a deletion command that leaves
as soon as you type them except for “colon” commands
the editor in insert mode. It is performed by typing c fol-
Counts
which execute when you press the return key.
lowed by a
. For example cw changes a word. A few
Nearly every command may be preceded by a number that
other change commands are:
specifies how many times it is to be performed. For exam-
Quitting
to end of line
C
ple 5dw will delete 5 words and 3fe will move the cursor
exit, saving changes
:x
line
forward to the 3rd occurance of the letter e. Even inser-
cc
quit (unless changes)
:q
tions may be repeated conveniently with this method, say
quit (force, even if unsaved)
:q!
Putting text
to insert the same line 100 times.
put after position or after line
p
Inserting text
Ranges
put before position or before line
P
insert before cursor, before line
i , I
Ranges may precede most “colon” commands and cause
append after cursor, after line
a , A
Registers
them to be executed on a line or lines. For example :3,7d
open new line after, line before
o , O
would delete lines 3 7. Ranges are commonly combined
Named registers may be specified before any deletion,
replace one char, many chars
r , R
with the :s command to perform a replacement on several
change, yank, or put command. The general prefix has
lines, as with :.,$s/pattern/string/g to make a replace-
the form "c where c may be any lower case letter. For
Motion
ment from the current line to the end of the file.
example, "adw deletes a word into register a. It may there-
left, down, up, right
h , j , k , l
after be put back into the text with an appropriate put
lines n-m
:n ,m
next word, blank delimited word
w , W
command, for example "ap.
current line
:.
beginning of word, of blank delimited word
b , B
last line
:$
end of word, of blank delimited word
e , E
Markers
marker c
:’c
sentence back, forward
( , )
Named markers may be set on any line of a file. Any lower
all lines
:%
paragraph back, forward
,
case letter may be a marker name. Markers may also be
all matching lines
:g/pattern /
beginning, end of line
0 , $
used as the limits for ranges.
beginning, end of file
1G , G
Files
set marker c on this line
mc
line n
n G or :n
write file (current file if no name given)
goto marker c
:w file
‘c
forward, back to char c
fc , Fc
append file (current file if no name given)
goto marker c first non-blank
:w >>file
’c
forward, back to before char c
tc , Tc
read file after line
:r file
top, middle, bottom of screen
H , M , L
Search for strings
read program output
:r !program
next file
:n
Deleting text
search forward
/string
previous file
:p
search backward
?string
Almost all deletion commands are performed by typing d
edit new file
:e file
repeat search in same, reverse direction
n , N
followed by a
. For example dw deletes a word. A
replace line with program output
:.!program
few other deletions are:
Replace
character to right, left
x , X
Other
The search and replace function is accomplished with the
to end of line
D
toggle upper/lower case
~
:s command. It is commonly used in combination with
line
dd
join lines
J
ranges or the :g command (below).
line
:d
repeat last text-changing command
.
replace pattern with string
:s/pattern /string /flags
undo last change, all changes on line
u , U
flags: all on each line, confirm each
g , c
repeat last :s command
&
c 2002 Donald J. Bindner – licensed under the terms of the GNU Free Documentation License version 1.1 or later.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go