Vim
By Sunrostern · · 3 min read
Vim Motions & Operations (Simple Guide)
Think of Vim as:
Verb (what to do) + Motion (where to do it)
Example:
dw= delete (d) word (w)y$= yank (y) to end of line ($)
MODES (you must know these)
Mode | What it Is | How to Enter |
|---|---|---|
Normal | Navigate & edit |
|
Insert | Type text |
|
Insert
Type text
i, a, o
Visual
Select text
v, V, Ctrl+v
Command
Run commands
:
👉 If Vim does something weird, press Esc twice.
BASIC MOVEMENT (the core)
Cursor movement
h left
j down
k up
l right
WORD MOVEMENT (very important)
w next word start
b previous word start
e end of word
Examples:
dw delete a word
yw copy a word
ce change until word end
LINE MOVEMENT
0 start of line
^ first non-space
$ end of line
Examples:
d$ delete to end of line
y^ copy to line start
FILE MOVEMENT
gg top of file
G bottom of file
Examples:
ggdG delete everything
ggyG copy everything
SEARCHING
/pattern search forward
?pattern search backward
n next match
N previous match
Example:
/foo
n
DELETE (CUT)
d{motion}
Examples:
dd delete line
dw delete word
d$ delete to end of line
dG delete to end of file
YANK (COPY)
y{motion}
Examples:
yy copy line
yw copy word
y$ copy to end of line
:%y copy whole file
To copy to system clipboard:
"+yy
"+y
PUT (PASTE)
p paste after cursor
P paste before cursor
CHANGE (DELETE + INSERT)
c{motion}
Examples:
cw change word
cc change whole line
c$ change to end of line
INSERT MODE SHORTCUTS
i insert before cursor
a insert after cursor
I insert at line start
A insert at line end
o new line below
O new line above
UNDO / REDO
u undo
Ctrl+r redo
VISUAL MODE (SELECTION)
v character selection
V line selection
Ctrl+v block selection
Then apply a command:
v + d delete selection
V + y copy lines
FIND CHARACTER (super fast)
fX find X forward
FX find X backward
tX before X
TX after X (backwards)
; repeat
, reverse repeat
Example:
dt, delete until comma
REPLACE
rX replace one character
R replace mode
SEARCH & REPLACE
:%s/old/new/g
Examples:
:%s/foo/bar/g
:%s/foo/bar/gc (ask each time)
MULTIPLE LINES AT ONCE
3dd delete 3 lines
5yy copy 5 lines
INDENTING
>> indent line
<< unindent line
Visual:
V + > indent selection
V + < unindent selection
COMMENTS (manual)
I# add comment at line start (visual mode)
COMMAND MODE ESSENTIALS
:w save
:q quit
:wq save & quit
:q! quit without saving
DELETE EVERYTHING (common ask)
:%d
Without copying:
:%d_
THE GOLDEN RULE
If you remember only one thing, remember this:
Vim = operator + motion
Examples:
d+w→ delete wordy+$→ copy to end of linec+G→ change to end of file
MINIMAL MUST-KNOW LIST (for real life)
If you can do these, you’re productive:
i,Escw b e0 ^ $d y c pdd yy/nu:%s