Show Menu
Cheatography

Motions

h, j, k, l
one char (left, down, up, right)
0, ^
line start (column 0, first char)
$
line end
f<c­har>
to next <ch­ar> in line
t<c­har>
f<c­har­>h
T<c­har>
t<c­har> but backwards
F<c­har>
f<c­har> but backwards
w, e
next word (start, end)
b
prev word (start)
W, E, B
stronger "­w", "­e", "­b"
(, )
start/end of sentence
{, }
start/end of paragraph
%
first or matching parenth
gg, G
file start, file end
Ctrl-u/d
half screen up/down
:<n­um>
jump to line
<nu­m>G
:<n­um>
Ctrl-o
undo movement
/<s­tr>
search forward in file
*
/<w­ord­_at­_po­sit­ion>
?<s­tr>
search backward in file
H, M, L
first/­mid­dle­/last line on screen
There are more motions, but these are the basic ones.

When used alone, motion moves the cursor.
It can also be used with operators.

When it makes sense, you can prefix motion with a count: e.g. "­3tg­" moves to third occurrence of g.

"­;" after "t <ch­ar>­" or "f <ch­ar>­" does one more search.
"­n" is next and "­N" is previous when doing search with "­/" or "­?".

Commands (Subst­itute)

:<­ran­ge>­s/<­old­>/<­new­>/[­flags]

range -> nothing (in line), #,# (between lines), % (whole file).
flags -> g (all occurr­ences), c (ask for confir­mat­ion), ...

:s/th­ee/the -> in line, first occurrence
:1,10­s/t­hee­/the/g -> from lines 1 to 10, all occurr­ences
:%s/t­hee­/th­e/gc -> whole file, all occurr­ences, ask for confir­mation

Concept: extending

Listed here are motions, operators, text-o­bjects and commands that come with vim. However, plugins (or you) can define new ones, bringing even more options!
 

Operators

c
change (delete and enter insert mode)
d
delete
y
yank (copy)
gu
make lowercase
gU
make uppercase
g~
toggle case
>
shift right
<
shift left
gq
text formatting
There are few other operators, but they are not used much.

Operators can be used as:
[count­]op­era­tor­([c­oun­t](­motion | text-o­bject))
e.g. d, 3d, d$, dw, d3w, 2d3w .

Combining operator with motion executes operator from current point to point where motion takes us.
Combining operator with text object executes operator on that text object.
Numbers (count) execute operator multiple times.

Typing an operator twice, e.g. dd or <<, usually executes the operator on current line.

Commands (Chang­e/I­nsert)

i, I
insert at point / line start
a, A
append after point / line end
o, O
open line below / above
r, R
rewrite one / many char(s)
C
c$
cc
c_
All these commands enter insert mode.

Commands (:)

:!<­cmd>
executes in external shell
:wqa
save all files and quit
:h<­smt­h>
help

Concept: composing

One of the best things in vim is composing its operators with motions and text-o­bjects! Commands can't be composed.

Here we will list some examples (check "­Ope­rat­ors­" for exact definition of compos­ition):

di( -> delete all inside ().
3tp or tp;; -> move to third occurence of p in line.
cip -> delete current paragraph and enter insert mode.
<2ib -> shift current block two times left.
 

Text objects

w
word
s
sentence
p
paragraph
', ", `
quotes
(, [, {, <
parent­heses
t
tag
_
current line (*)
Text objects are not to be used alone, but in combin­ation with e.g. operators.

Text objects can be combined with modifiers "­a" (around) and "­i" (inside) to create new text objects, e.g. iw (word we are inside of), or aw (word and surrou­nding spaces).

(*) _ is not really a text object, but it behaves mostly like one.

Commands (Deletion)

x, X
delete one char (after, before)
D
d$
dd
d_
J
join current with next line

Commands (Visual)

v
select from point
V
select from line
Ctrl-v
select from point as block
All these commands enter visual mode.

Commands (Other)

yy
y_
p
paste
.
repeat last command
u
undo
Ctrl-r
redo
zz
center screen on point
za, zm, zr
code folding

Concept: modes

While in normal mode, we can do all the fun stuff: commands, operators, movements, and entering other modes.

While in insert mode, we are inserting text.

While in visual mode, we are selecting text.

Credits

   
 

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
          Spacemacs (+Clojure) Keyboard Shortcuts