You are on page 1of 2

VIM Quick Reference Card

Basic movement

h

l

k

j

character

left, right, line

up, down

b

w

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

word/token

left, right

ge

e

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

end of word/token left, right

{

}

beginning

of

previous, next

paragraph

(

)

beginning

of

previous,

0

gm

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

beginning,

next sentence middle of line

^

nG

$

.

ngg

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

first,

n,

.

line

.

last character of line default the last, first

n%

 

percentage n

of the file (n must be provided)

n|

column n of current line

Insert mode

 

ˆVc

insert char c literally

.insert decimal value of

character

ˆA

insert previously inserted text

ˆRx

.same as ˆA and stop insert command mode insert content of register x

ˆN ˆP

ˆW ˆU ˆD ˆK c 1 esc

.

c 2

.

.

.

.

.

.

.

.

completion before, after cursor delete word before

cursor delete all inserted character in current line

shift left one shift width

enter digraph

. abandon edition command mode

text

.

.

.

.

.

.

.

.

Undoing & repeating commands

u U

.

n.

qc qC

undo last command, restore last changed line

.repeat last changes, redo last undo

repeat last changes with count replaced by n .record, append typed characters in register c

q

@c

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. execute the content of register c

recording

stop

.

.

.

.

.

.

.

.

.

.

.

.

.

.

@@

.

:@c

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.execute

.

.

.

.

.

.

.

.

. register c as an Ex command

previous @ command

repeat

:rg/p/c

Complex movement

execute Ex command c on range r where pattern p matches

 

.match of next brace, bracket, comment, #define

 

- +

 

line up/down on first non-blank character

nH

 

nL

 

line n from start, bottom

of window

Copying

 

B W

 

space-separated

word left, right

M

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

middle

line

of window

"x

 

use

 

register x for next delete, yank, put

E

 

end

of

 
 

.

.

.

.

.

.

.

.

.

.

.

.

 

:reg

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

gE

n

.

.

.

.

.

.

.

.

.

.

.

.

.

.

space-separated word left, right

down n 1 line on first non-blank character

.

.

.

.

.

Insertion & replace insert mode

 

:reg

x

 

show the content of all registers show the content of registers x the text of movement command m

g0

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

beginning

of screen line

i

a

insert before, after

cursor

ym

 

yank

 

g^

g$

 

.

.

.

.

.

.

.

first,

 

last character of screen line

I

 

A

 

insert at beginning, end of line

yy or

Y

.

.

.

.

.

.

.

.

.

yank

current

line into register

gk

gj

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

screen

line up, down

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

   

gI

o

.

O

.

.

.

.

.

.

first column

open a new line below, above the current line

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

insert

text in

p

]p

P

.

[p

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

put

.

.

.

.

register

.

after, before cursor position

p, P with indent adjusted

.

.

like

.

.

fc

tc

Fc

Tc

 

next, previous occurence of character c

c

before next, previous occurence of

rc

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

replace character under cursor with c

gp

gP

.

.

.

.

.

.

.

.

.

.

.

like

. p, P leaving cursor after new text

;

,

.

.

.

.

.

.

repeat

 

last fFtT, in opposite direction

grc

 

like r, but without affecting

layout

 

[[

]]

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

start of section backward, forward

R

replace characters starting at the

cursor

Advanced insertion

 

[]

][

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

end

 

of section backward, forward

gR

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

like

 

R, but without affecting layout

[(

])

 

unclosed

 

(, )

backward, forward

cm

.

.

.

.

.

.

.

.

.

.

.

.

.

change text of movement command m

g?m

 

perform rot13 encoding on movement m

[{

[}

 

unclosed {, }

backward, forward

cc

or S

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

change

current

line

nˆA nˆX

 

+n, n to number under cursor

[m

]m

 

start, end of backward, forward java method

C

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

change

to

the end of

line

gqm

 

format lines of movement m to fixed width

[#

[*

]# . unclosed #if, #else, #endif backward, forward

]*

backward, forward

start,

end

of /*

*/

s

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

change

one character and insert

:rce

w

 

center lines in range r

to width w

~

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

switch

case and advance cursor

:rle

i

 

left align lines in range r with indent i right align lines in range r to width w

           

g~m

.

.

.

.

.

.

.

.

.

.

.

.

switch

case of movement command m

:rri

w

 

gum gUm

 

lowercase, uppercase text of movement m

!mc . filter lines of movement m through command c

Search & substitution

 

<m >m

 

shift left, right

text of movement m

n!!c

 

filter n

lines through command c

 

search forward, backward for

s

n<<

n>>

 

shift n lines left, right

:r!c

 

filter range r lines through command c

/s ?s /s/o ?s?o

search fwd, bwd for s with offset o

 

n

or /

 

repeat forward

last search

Deletion

 

N

or ?

 

repeat backward

last search

x

X

.

.

.

.

.

.

.

.

.

.

.

.

.

.

delete

character under, before cursor

Visual mode

 

#

*

search backward, forward for word under cursor same, but also find partial matches local, global definition of symbol under cursor

dm

 

delete text of movement command m

v

V

ˆV

 

start/stop highlighting characters, lines, block

g#

g*

 

dd

 

D

delete current line, to the end of line

o

exchange cursor position with start of highlighting start highlighting on previous visual area

gd

gD

J

gJ

 

join current line with next, without space delete range r lines delete range r lines into register x

gv

:rs/f /t/x

 

substitute f by t in range r

:rd

 

aw

as ap

 

select a word, a sentence, a paragraph select a block ( ), a block { }

 

x : g—all occurrences, c—confirm changes repeat substitution with new r & x

:rdx

 

ab

aB

 

:rs x

 

Special characters in search patterns ˆ

.

any single character, start of line

\<

[c 1

\>

2 ]

c

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

start,

end of word

c

2

. a single character in range c 1

.

.

.

.

.

[ˆc 1

c 2 ]

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

a

single

character not in

range

\i

\I

 

an identifier,

excluding digits

\k

\K

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

a

keyword,

excluding digits

\f

\p

\F

\P

.

.

.

.

.

.

.

.

.

.

.

. a printable character, excluding digits

file name, excluding digits

.

.

.

.

.

.

.

.

a

\s

\S

 

a white space,

a non-white

\e

\t

\r

\b

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

esc ,

tab ,

space ,

\=

*

\+

 

match

 

0

1,

0

,

1

of preceding atoms

\|

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

separate two branches (or)

\(

\)

group patterns into an atom

Offsets in search commands

n or +n

. e+n e-n s+n ;sc

.

-n

.

.

.

.

.

.

.

.

.

.

n line downward in column 1

. n characters right, left to end of match n characters right, left to start of match execute search command sc next

. n line upward in column 1

.

.

.

.

.

.

.

.

.

.

.

Marks and motions

mc

mark current position with mark c [a

Z]

c

0

C

9

.

.

.

.

.

.

.

.

.

.

.

.

.

go to mark c in current,

.

to last

.

.

.

.

.

.

.

.

.

.

.

.

go

C in any file exit position

‘‘

‘" .

.

.

.

.

.

go

to position

. before jump, at last edit

‘[

‘]

 

go to start, end of previously operated text

:marks

print the active marks

list

:jumps

print the

jump list

nˆO

go to n th older

position in jump list

nˆI

go to n th newer

position in jump list

Tags

:ta

t

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

jump to tag t

:nta

jump

to n th newer tag in list

ˆ] ˆT

jump to the tag under cursor, return from tag

:ts

t

list matching tags and select one for jump

:tj

t

jump to tag or select one if multiple matches

:tags

:nˆT

.

.

.

.

.

.

.

.

.

.

jump

.

.

.

.

.

.

.

.

.

back

.

.

.

to

.

. n th older tag in tag list

tag list

.

.

.

.

.

.

.

.

.

print

:npo

 

jump back from n th older tag in tag list

:tl

 

jump to last matching

tag

ˆW{ :pt t

 

preview tag under cursor, tag t

close tag preview window

. ˆWz or :pc

ˆW]

.

.

.

.

.

.

.

.

.

.

split window and show tag under cursor

Scrolling & multi-windowing

ˆE

ˆD ˆU

ˆY

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. scroll half a page up, down

line up, down

.

.

.

.

.

.

scroll

ˆF ˆB

zt or z zz or z.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

scroll

. set current line

.

.

.

.

.

.

.

.

.

.

.

set current line at

page up, down

at top of window center of window

zb or z-

 

set

current line at bottom

of window

zh

zl

scroll one character

to the right, left

zH

zL

scroll half a screen

to the right, left

ˆWs or :split

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

split

ˆWn or :new

 

.create new

window in two empty window

ˆWo or :on ˆWj ˆWk ˆWw

 

make current window one on screen move to window below, above .move to window below, above (wrap)

Ex commands ( )

Ex ranges

,

;

separates two lines numbers, set to first line

n

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

an

absolute line number n

.

$

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

the

current line, the last line in file

%

*

entire file, visual area

t

.

/p/ ?p?

.

.

.

.

.

 

.

.

.

.

.

.

.

. the next, previous line where p matches

of mark t

.

position

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

+n -n

+n, n to the preceding line number

Miscellaneous

:sh

:!c

start shell, execute command c in shell

lookup keyword under cursor with man

start make, read errors and jump to first

display the next, previous error list all errors, read errors from file

redraw screen, show filename and position

K

:make

:cn

:cl

ˆL ˆG

:cp

:cf

gˆG

show cursor column, line, and character position

ga

show ASCII value of character under cursor

:redir>f

.open file which filename is under cursor

redirect output to file f

:e

f

f

edit file f , unless changes have been made

:e!

edit file f always (by default reload current)

:wn

:wN

write

file and

edit next, previous one

:n

:N

edit next, previous file

in

list

Key mapping & abbreviations

:map

c

e

 

:rw

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

write range r to current file

e in normal

& visual mode

:rw

f

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.write

:map!

:unmap

c

e

c

.map c

map c :unmap!

c

e in insert & cmd-line mode remove mapping c

:rw>>f

:q

:q!

 

range r to file f range r to file f

quit & confirm, quit and discard changes

append

:mk

f

e

write current mappings, settings

to file f

:wq or :x or ZZ

:r

write

to current

file and exit

:ab

:ab

c c

show

abbreviations starting with c

add abbreviation for c

e

up down f

recall commands starting with current

of file f below cursor

insert content

:una

c

remove abbreviation

c

:r!

insert output of command c below cursor

This card may be freely distributed under the terms of the GNU general public licence — Copyright c  by Laurent Gr´egoire laurent.gregoire@icam.fr — v1.2 — The author assumes no responsability for any errors on this card.