VIM tips

Stuff I always forget ...

Learning Vim is a slow but worthwhile journey. I'm noting some of the commands here until they become automatic.

Movement

Key What does it do
w Move to beginning of next word
b Move back to beginning of previous word
e Move to end of word
`Shift + [ ]`
0 Move to start of line
$ Move to end of line
I Move to start of line and switch to insert mode
A Move to end of line and switch to insert mode (append)
i Insert before cursor
a Insert after cursor (append)
% Find matching parenthesis
Key What does it do
/<query> Find query forwards
?<query> Find query backwards
n Find again
N Find again reverse direction
Ctrl + O Go back
Ctrl + I Go forward

Substitute

Key What does it do
:%s/find/replace/g[c] Find and replace (c = confirm, % = all lines)
:#,#s/find/replace/g Find and replace between lines numbers #,#

Editing

Key What does it do
v Select range of text
V Select text by line
y Copy (yank)
p Paste
P Paste before cursor
u Undo
U Undo changes to line
dd Delete line
yy Copy line (yank)
dw Delete word
d$ Delete to end of line
cw Change to end of word
c$ Change to end of line
r Replace current char
R Replace more than one char
ve or viw Select current word
~ Change case
vt<char> Select up to char
dt<char> Delete up to char
vf<char> Select forward through (including) char
df<char> Delete forward through (including) char
vT<char> Select up to char backwards (capital T/F)
v2t<char> Select up to 2nd instance of char
:%s/find/replace/g[c] Find and replace (c = confirm)