vim - the perfect cheat sheet

I copied this useful cheat sheet from "Command Line Warriors" blog. Check out their blog for more.

Command Mode ESC
Insert Mode i

Movement commands

h, j, k, l left, down, up, right
w, W, b, B forward, backward by word
H highest line of the screen
M middle line of the screen
L lowest line of the screen
Ctrl-F forward one screen
Ctrl-B backward one screen
Ctrl-D halfway down (i.e. forward) the screen
Ctrl-U halfway up (i.e. back) the screen
0 (zero), $ start, end of current line

Inserting text

a append after cursor
i insert before cursor
A append to end of line
I insert at start of line
o open a line below current line
O open a line above current line
r replace char

Delete text

x current character
dh previous character
dw current word
db previous word
dd entire line
d$ to end of line
d0 (zero) to start of line
ndd next n lines


p insert after cursor
P insert before cursor

Goto line

nG Goto line n
:7 Goto line 7

Save and exit

ZZ write if changes and quit
:wq write and quit
:w filename save to new file
:q! quit vi
:x save & quit (Thanks for the tip Jan!)


/pattern forward for a pattern
?pattern backward for a pattern
n repeat previous search
N repeat previous search in reverse direction

Search and replace


* Search from current line and replace first occurance
* Search from current line and replace all matches
* Search from every line, replace confirmation (with [y]es)
* Search lines from 10 to 20


u the latest change
U all changes on a line

J concatenate two lines
Post a Comment