Show Menu
Cheatography

A cheatsheet for Vim motions.

FIND AND REPLACE

:%s/fo­o/bar/g
Replace whole file
:%s/\<­cat­\>/­dog/g
Whole word
:[rang­e]s­/{p­att­ern­}/{­rep­lac­eme­nt}­/{f­lags}

Range

(empty)
Current line
%
Entire file
.,$
Current line to end of file
10,20
Line 10 to line 20
,
== "­to"
.
== "­current line"
$
== "end of file"

Flags

g
Replace all occurr­ences in given range
c
Ask for confir­mation
i
Ignore case
I
Case sensitive
n
Print count only, does not make any changes

Macros

q {register}
Record to register
{register}
q
Stop recording
@{regi­ster}
Play macro
Macros are a motion, which means doing
5j@a
is valid
 

VERTICAL MOVEMENT

j
Down 1 line
k
Up 1 line
10j
Down 10 lines
10k
Up 10 lines

Screen­/Page Movement

Ctrl-d
Half-page down
Ctrl-u
Half-page up
H
Go to top of the current screen (High)
L
Go to bottom of the current screen (Low)
M
Go to middle of the current screen (Middle)
{
Jump to the previous paragr­­ap­h­/­block
}
Jump to the next paragr­­ap­h­/­block
These matter for covering distance fast

Insertion

I
Insert at start of line
A
Append
at end of line
o
New line below
O
New line above

Large-­Scale Movement

gg
Go to first line (top of file)
G
Go to last line (bottom of file)
123G
or
:123
Go to line 123
 

HORIZONTAL MOVEMENT

h
Move left 1 character
l
Move right 1 character
w
Start of next word
b
Start of previous word (Back)
e
End of curren­t/next word

WORD Movement

W
Next WORD
B
Previous WORD
E
End of WORD
some_v­ar=­value
,
path/t­o/file
,
foo(bar)
are all WORDS

Precision Movement

0
Go to column 0 (absolute start of line)
^
Go to first non-blank of line
$
Go to end of line
f\<­cha­r\>
Move to the next occurrence of
<ch­ar>
F\<­cha­r\>
Move to the previous occurrence of
<ch­ar>
t\<­cha­r\>
Move before the next occurrence
T\<­cha­r\>
Move before the previous occurr­ence.

Operators

d
Delete
c
Change (delete + insert)
y
Yank (copy)
~
Flip case
gu
To lowercase
gU
To uppercase
 
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          VI Editor Cheat Sheet
          Vim NERDTree Cheat Sheet
          Helix Keyboard Shortcuts