VIM Cheatsheet

Basic commands

Stuff

Exit

The thing no one knows how to do

:q
Close file
:qa
Close all files
:w
Save
:wq
Save and close file
:x
Save and close file
ZZ
Save and quit
ZQ
Quit without checking changes
Esc / <C-[>
Exit insert mode
<C-C>
Exit insert mode, and abort current command

Word Navigation

Every day I'm traveling

h / j / k / l
Arrow keys
<C-U> / <C-D>
Half-page up/down
<C-B> / <C-F>
Page up/down
b / w
Previous/next word
ge / e
Previous/next end of word
0
Start of line
^
Start of line (after whitespace)
$
End of line

Document Navigation

Every day I'm traveling

f{character}
Go forward to a character
F{character}
Go backward to a character
gg
First line
G
Last line
:{number}
Go to line {number}
{number}G
Go to line {number}
{number}j
Go down {number} of lines
{number}k
Go up {number} of lines

Editing

Splash

a
Append
A
Append from end of line
i
Insert
o
Next line
O
Previous line
s
Delete char and insert
S
Delete line and insert
C
Delete until end of line and insert
r
Replace one character
R
Enter Replace mode
u
Undo changes
<C-R>
Redo changes

Visual Mode

Splash

v
Enter visual mode
V
Enter visual line mode
<C-V>
Enter visual block mode
d / x
Delete selection
s
Replace selection
y
Yank selection (Copy)

Clipboard

Splash

x
Delete character
dd
Delete line (Cut)
yy
Yank line (Copy)
p
Paste
P
Paste before
"*p / "+p
Paste from system clipboard
"*y / "+y
Paste to system clipboard

Operators

Operators let you operate in a range of text (defined by motion). These are performed in normal mode.

Operators list

See :help operator

d
Delete
y
Yank (copy)
c
Change (delete then insert)
>
Indent right
<
Indent left
=
Autoindent
g~
Swap case
gU / gu
Uppercase / Lowercase
!
Filter through external program

Examples

Combine operators with motions to use them.

dd
(repeat the letter) Delete current line
dw
Delete to next word
db
Delete to beginning of word
2dd
Delete 2 lines
dip
Delete a text object (inside paragraph)
(in visual mode) d
Delete selection

Text objects

Text objects let you operate (with an operator) in or around text blocks (objects).

Text objects

See :help text object

p
Paragraph
w
Word
s
Sentence
[ ( { <
A [], (), or {} block
' " `
A quoted string
b
A block [(
B
A block in [{
t
A XML tag block

Examples

See Operators for other things you can do.

vip
Select paragraph
vipipipip
Select more
yip
Yank inner paragraph
yap
Yank paragraph (including newline)
dip
Delete inner paragraph
cip
Change inner paragraph