Você está na página 1de 1

Vi Reference Card

Yanking text

Regular expressions

 

Like deletion, almost all yank commands are performed by

any single character except newline

.

(dot)

Modes

Vi

has two modes: insertion mode, and command mode.

typing y followed by a motion. For example y$ yanks to the end of line. Two other yank commands are:

zero or more repeats any character in set any character not in set

[^

[

*

]

]

The editor begins in command mode, where cursor move-

as

soon as you type them except for “colon” commands

Quitting

line

yy

beginning, end of line

^

$

ment and text deletion and pasting occur. Insertion mode

line

:y

beginning, end of word

\<

,

,

\>

begins upon entering an insertion or change command.

 

grouping

\)

[ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute

Changing text

The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c fol-

C

contents of n th grouping

\n

which execute when you press the return key.

lowed by a motion. For example cw changes a word. A few other change commands are:

Counts

Nearly every command may be preceded by a number that specifies how many times it is to be performed. For exam- ple 5dw will delete 5 words and 3fe will move the cursor

exit, saving changes

 

:x

to end of line

 

line

cc

forward to the 3rd occurance of the letter e. Even inser-

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.

Inserting text

 

put after position or after line

 

p

put before position or before line

P

Ranges

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

Named registers may be specified before any deletion,

would delete lines 37. Ranges are commonly combined

replace one char, many chars

r

,

R

change, yank, or put command. The general prefix has

with the :s command to perform a replacement on several

Motion

 

the form "c where c may be any lower case letter. For example, "adw deletes a word into register a. It may there-

lines, as with :.,$s/pattern/string/g to make a replace- ment from the current line to the end of the file.

left, down, up, right

h

,

j

,

k

,

l

after be put back into the text with an appropriate put

next word, blank delimited word

 

w

,

W

command, for example "ap.

lines n-m

:n ,m

b

 

B

current line

:.

beginning of word, of blank delimited word

 

,

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

 

paragraph back, forward

{

,

}

case letter may be a marker name. Markers may also be

all lines all matching lines

:%

:g/pattern /

beginning, end of line

0

,

$

used as the limits for ranges.

beginning, end of file

 

1G

 

,

G

Files

 

line n

n G

or :n

set marker c on this line

mc

forward, back to char c

fc

,

Fc

goto marker c

c

write file (current file if no name given)

:w

file

forward, back to before char c

tc

,

Tc

goto marker c first non-blank

c

append file (current file if no name given)

:w

>>file

top, middle, bottom of screen

 

H

,

M

,

L

Search for strings

read file after line read program output

:r

file

!program

:r

Deleting text

 

search forward

/string

?string

next file

:n

Almost all deletion commands are performed by typing d

previous file

:prev

followed by a motion. For example dw deletes a word. A

search backward repeat search in same, reverse direction

n

,

N

edit new file

:e

file

few other deletions are:

 

replace line with program output

:.!program

character to right, left

 

Replace

 

x

,

X

The search and replace function is accomplished with the

Other

to

end of line

D

toggle upper/lower case

~

line

dd

:s command. It is commonly used in combination with ranges or the :g command (below).

join lines

 

J

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-2005 Donald J. Bindner – licensed under the terms of the GNU General Public License 2.0 or later.