Vim Commands Reference - Complete Vi/Vim Editor Guide

Quick reference guide for Vi/Vim editor commands and shortcuts

Navigation

h
Move cursor left
j
Move cursor down
k
Move cursor up
l
Move cursor right
w
Move to next word
b
Move to previous word
0
Move to beginning of line
$
Move to end of line
gg
Go to beginning of file
G
Go to end of file
Ctrl+f
Page down
Ctrl+b
Page up

Editing

i
Enter insert mode
a
Append after cursor
o
New line below
O
New line above
Esc
Return to normal mode
x
Delete character under cursor
dd
Delete entire line
yy
Copy (yank) line
p
Paste after cursor
u
Undo
Ctrl+r
Redo
r
Replace character

Visual Mode

v
Visual character mode
V
Visual line mode
Ctrl+v
Visual block mode
y
Yank (copy) selected text
d
Delete selected text
>
Indent selected text
<
Unindent selected text

Search & Replace

/pattern
Search forward
?pattern
Search backward
n
Next search match
N
Previous search match
:s/old/new
Replace in current line
:%s/old/new/g
Replace all in file
*
Search word under cursor

Files & Buffers

:w
Save file
:q
Quit
:wq
Save and quit
:q!
Force quit (discard changes)
:e filename
Open file
:sp
Split window horizontally
:vsp
Split window vertically
Ctrl+w
Switch between windows

Advanced

.
Repeat last command
q[a-z]
Record macro
@[a-z]
Play macro
:set nu
Show line numbers
:set paste
Enter paste mode
:%!xxd
Switch to hex mode
:!cmd
Execute shell command
ZZ
Save and quit (shortcut)