VIM Cheat Sheet
Master VIM with this comprehensive reference guide. Find commands, shortcuts, and examples with this cheat sheet.
h
NavigationMove cursor left
Syntax:
h
Examples:
h
Move one character to the left5h
Move five characters to the leftNotes:
Basic cursor movement command
j
NavigationMove cursor down
Syntax:
j
Examples:
j
Move one line down10j
Move ten lines downNotes:
Basic cursor movement command
k
NavigationMove cursor up
Syntax:
k
Examples:
k
Move one line up3k
Move three lines upNotes:
Basic cursor movement command
l
NavigationMove cursor right
Syntax:
l
Examples:
l
Move one character to the right7l
Move seven characters to the rightNotes:
Basic cursor movement command
w
NavigationMove to beginning of next word
Syntax:
w
Examples:
w
Move to next word3w
Move forward 3 wordsNotes:
Stops at punctuation
W
NavigationMove to beginning of next WORD (whitespace separated)
Syntax:
W
Examples:
W
Move to next whitespace-separated word2W
Move forward 2 WORDsNotes:
Ignores punctuation, only stops at whitespace
b
NavigationMove to beginning of previous word
Syntax:
b
Examples:
b
Move to previous word2b
Move back 2 wordsNotes:
Stops at punctuation
B
NavigationMove to beginning of previous WORD (whitespace separated)
Syntax:
B
Examples:
B
Move to previous whitespace-separated word3B
Move back 3 WORDsNotes:
Ignores punctuation
e
NavigationMove to end of current word
Syntax:
e
Examples:
e
Move to end of word4e
Move to end of 4th word aheadNotes:
Useful for selecting to end of word
E
NavigationMove to end of current WORD (whitespace separated)
Syntax:
E
Examples:
E
Move to end of WORD2E
Move to end of 2nd WORD aheadNotes:
Ignores punctuation
0
NavigationMove to beginning of line
Syntax:
0
Examples:
0
Move to start of current lineNotes:
Goes to column 0
^
NavigationMove to first non-blank character of line
Syntax:
^
Examples:
^
Move to first non-whitespace characterNotes:
Skips leading whitespace
$
NavigationMove to end of line
Syntax:
$
Examples:
$
Move to end of current line3$
Move to end of line 3 lines downNotes:
Useful for line editing
gg
NavigationGo to first line of file
Syntax:
gg
Examples:
gg
Go to beginning of file5gg
Go to line 5Notes:
Quick way to navigate to top
G
NavigationGo to last line of file
Syntax:
G
Examples:
G
Go to end of file10G
Go to line 10Notes:
Quick way to navigate to bottom
Ctrl+u
NavigationScroll up half page
Syntax:
Ctrl+u
Examples:
Ctrl+u
Move half page upNotes:
Half page scroll
Ctrl+d
NavigationScroll down half page
Syntax:
Ctrl+d
Examples:
Ctrl+d
Move half page downNotes:
Half page scroll
Ctrl+f
NavigationPage down
Syntax:
Ctrl+f
Examples:
Ctrl+f
Move one page downNotes:
Full page scroll
Ctrl+b
NavigationPage up
Syntax:
Ctrl+b
Examples:
Ctrl+b
Move one page upNotes:
Full page scroll
f{char}
NavigationFind next occurrence of character in line
Syntax:
f{character}
Examples:
fa
Move to next 'a' in current linef;
Move to next ';' in current lineNotes:
Cursor lands on the character
F{char}
NavigationFind previous occurrence of character in line
Syntax:
F{character}
Examples:
Fa
Move to previous 'a' in current lineF(
Move to previous '(' in current lineNotes:
Searches backwards in line
t{char}
NavigationMove to (before) next occurrence of character
Syntax:
t{character}
Examples:
ta
Move to just before next 'a't)
Move to just before next ')'Notes:
Cursor stops one character before target
T{char}
NavigationMove to (after) previous occurrence of character
Syntax:
T{character}
Examples:
Ta
Move to just after previous 'a'T,
Move to just after previous ','Notes:
Searches backwards, stops after character
%
NavigationJump to matching bracket/parenthesis
Syntax:
%
Examples:
%
Jump from ( to ) or from { to }Notes:
Works with (), [], {}, and more
i
Insert ModeInsert before cursor
Syntax:
i
Examples:
i
Enter insert mode before cursorNotes:
Most common way to start editing
I
Insert ModeInsert at beginning of line
Syntax:
I
Examples:
I
Move to start of line and enter insert modeNotes:
Equivalent to ^i
a
Insert ModeInsert after cursor
Syntax:
a
Examples:
a
Enter insert mode after cursorNotes:
Useful for appending
A
Insert ModeInsert at end of line
Syntax:
A
Examples:
A
Move to end of line and enter insert modeNotes:
Equivalent to $a
o
Insert ModeOpen new line below
Syntax:
o
Examples:
o
Create new line below and enter insert modeNotes:
Creates line and enters insert mode
O
Insert ModeOpen new line above
Syntax:
O
Examples:
O
Create new line above and enter insert modeNotes:
Creates line and enters insert mode
s
Insert ModeSubstitute character
Syntax:
s
Examples:
s
Delete character under cursor and enter insert mode3s
Delete 3 characters and enter insert modeNotes:
Combination of x and i
S
Insert ModeSubstitute line
Syntax:
S
Examples:
S
Delete entire line and enter insert modeNotes:
Equivalent to cc
x
DeleteDelete character under cursor
Syntax:
x
Examples:
x
Delete current character5x
Delete 5 charactersNotes:
Like pressing Delete key
X
DeleteDelete character before cursor
Syntax:
X
Examples:
X
Delete character to the left3X
Delete 3 characters to the leftNotes:
Like pressing Backspace
dd
DeleteDelete entire line
Syntax:
dd
Examples:
dd
Delete current line3dd
Delete 3 lines starting from currentNotes:
Line goes to default register
dw
DeleteDelete word
Syntax:
dw
Examples:
dw
Delete from cursor to end of word2dw
Delete 2 wordsNotes:
Includes trailing whitespace
de
DeleteDelete to end of word
Syntax:
de
Examples:
de
Delete to end of current wordNotes:
Doesn't include trailing whitespace
d$
DeleteDelete to end of line
Syntax:
d$
Examples:
d$
Delete from cursor to end of lineNotes:
Also available as D
d0
DeleteDelete to beginning of line
Syntax:
d0
Examples:
d0
Delete from cursor to start of lineNotes:
Doesn't delete the character under cursor
dgg
DeleteDelete to beginning of file
Syntax:
dgg
Examples:
dgg
Delete from cursor to start of fileNotes:
Deletes all lines above and current line
dG
DeleteDelete to end of file
Syntax:
dG
Examples:
dG
Delete from cursor to end of fileNotes:
Deletes current line and all lines below
yy
CopyYank (copy) entire line
Syntax:
yy
Examples:
yy
Copy current line3yy
Copy 3 lines starting from currentNotes:
Line goes to default register
yw
CopyYank word
Syntax:
yw
Examples:
yw
Copy word from cursor2yw
Copy 2 wordsNotes:
Includes trailing whitespace
ye
CopyYank to end of word
Syntax:
ye
Examples:
ye
Copy to end of current wordNotes:
Doesn't include trailing whitespace
y$
CopyYank to end of line
Syntax:
y$
Examples:
y$
Copy from cursor to end of lineNotes:
Also available as Y
y0
CopyYank to beginning of line
Syntax:
y0
Examples:
y0
Copy from cursor to start of lineNotes:
Doesn't include character under cursor
ygg
CopyYank to beginning of file
Syntax:
ygg
Examples:
ygg
Copy from cursor to start of fileNotes:
Copies all lines above and current line
yG
CopyYank to end of file
Syntax:
yG
Examples:
yG
Copy from cursor to end of fileNotes:
Copies current line and all lines below
p
PastePaste after cursor
Syntax:
p
Examples:
p
Paste after cursor or below current line3p
Paste 3 timesNotes:
Paste location depends on what was copied
P
PastePaste before cursor
Syntax:
P
Examples:
P
Paste before cursor or above current lineNotes:
Opposite of p
cc
ChangeChange entire line
Syntax:
cc
Examples:
cc
Delete line and enter insert mode2cc
Change 2 linesNotes:
Equivalent to S
cw
ChangeChange word
Syntax:
cw
Examples:
cw
Delete word and enter insert mode3cw
Change 3 wordsNotes:
Delete and insert in one command
ce
ChangeChange to end of word
Syntax:
ce
Examples:
ce
Change to end of current wordNotes:
Doesn't include trailing whitespace
c$
ChangeChange to end of line
Syntax:
c$
Examples:
c$
Delete to end of line and enter insert modeNotes:
Also available as C
c0
ChangeChange to beginning of line
Syntax:
c0
Examples:
c0
Delete to start of line and enter insert modeNotes:
Doesn't delete character under cursor
/pattern
SearchSearch forward for pattern
Syntax:
/pattern
Examples:
/hello
Search for 'hello' going forward/\d\+
Search for one or more digits (regex)Notes:
Use Enter to execute search
?pattern
SearchSearch backward for pattern
Syntax:
?pattern
Examples:
?hello
Search for 'hello' going backward?function
Search for 'function' backwardNotes:
Use Enter to execute search
n
SearchNext search result
Syntax:
n
Examples:
n
Go to next match in same directionNotes:
Repeats last search in same direction
N
SearchPrevious search result
Syntax:
N
Examples:
N
Go to next match in opposite directionNotes:
Repeats last search in opposite direction
*
SearchSearch for word under cursor (forward)
Syntax:
*
Examples:
*
Search forward for word under cursorNotes:
Matches whole words only
#
SearchSearch for word under cursor (backward)
Syntax:
#
Examples:
#
Search backward for word under cursorNotes:
Matches whole words only
:s/old/new/
Search & ReplaceSubstitute first occurrence in current line
Syntax:
:s/old/new/[flags]
Examples:
:s/hello/hi/
Replace first 'hello' with 'hi' in current line:s/old/new/g
Replace all 'old' with 'new' in current lineNotes:
Add 'g' flag for global replacement in line
:%s/old/new/g
Search & ReplaceSubstitute all occurrences in file
Syntax:
:%s/old/new/[flags]
Examples:
:%s/hello/hi/g
Replace all 'hello' with 'hi' in entire file:%s/old/new/gc
Replace all with confirmation promptNotes:
% means entire file, g means global, c means confirm
:1,10s/old/new/g
Search & ReplaceSubstitute in range of lines
Syntax:
:start,ends/old/new/[flags]
Examples:
:1,10s/foo/bar/g
Replace 'foo' with 'bar' in lines 1-10:.,$s/old/new/g
Replace from current line to end of fileNotes:
. means current line, $ means last line
:w
File OperationsSave file
Syntax:
:w [filename]
Examples:
:w
Save current file:w newfile.txt
Save as newfile.txtNotes:
Most common save command
:wq
File OperationsSave and quit
Syntax:
:wq
Examples:
:wq
Save file and exit vimZZ
Alternative: save and quitNotes:
ZZ is equivalent shortcut
:q
File OperationsQuit
Syntax:
:q[!]
Examples:
:q
Quit if no changes:q!
Quit without saving changesNotes:
Use ! to force quit without saving
:e
File OperationsEdit file
Syntax:
:e [filename]
Examples:
:e file.txt
Open file.txt:e!
Reload current file (discard changes)Notes:
! reloads current file
:new
File OperationsCreate new file in horizontal split
Syntax:
:new [filename]
Examples:
:new
Create new unnamed file:new file.txt
Create new file named file.txtNotes:
Opens in horizontal split
:vnew
File OperationsCreate new file in vertical split
Syntax:
:vnew [filename]
Examples:
:vnew
Create new unnamed file vertically:vnew file.txt
Create new file in vertical splitNotes:
Opens in vertical split
:split
WindowsSplit window horizontally
Syntax:
:split [filename]
Examples:
:split
Split current window horizontally:split file.txt
Split and open file.txtNotes:
Also available as :sp
:vsplit
WindowsSplit window vertically
Syntax:
:vsplit [filename]
Examples:
:vsplit
Split current window vertically:vsplit file.txt
Split vertically and open file.txtNotes:
Also available as :vsp
Ctrl+w w
WindowsSwitch between windows
Syntax:
Ctrl+w w
Examples:
Ctrl+w w
Move to next windowNotes:
Cycles through all windows
Ctrl+w h
WindowsMove to left window
Syntax:
Ctrl+w h
Examples:
Ctrl+w h
Move to window on the leftNotes:
Directional window navigation
Ctrl+w j
WindowsMove to window below
Syntax:
Ctrl+w j
Examples:
Ctrl+w j
Move to window belowNotes:
Directional window navigation
Ctrl+w k
WindowsMove to window above
Syntax:
Ctrl+w k
Examples:
Ctrl+w k
Move to window aboveNotes:
Directional window navigation
Ctrl+w l
WindowsMove to right window
Syntax:
Ctrl+w l
Examples:
Ctrl+w l
Move to window on the rightNotes:
Directional window navigation
Ctrl+w q
WindowsClose current window
Syntax:
Ctrl+w q
Examples:
Ctrl+w q
Close current windowNotes:
Equivalent to :q
Ctrl+w o
WindowsClose all other windows
Syntax:
Ctrl+w o
Examples:
Ctrl+w o
Keep only current windowNotes:
Makes current window the only window
:tabnew
TabsOpen new tab
Syntax:
:tabnew [filename]
Examples:
:tabnew
Create new empty tab:tabnew file.txt
Open file.txt in new tabNotes:
Opens new tab with file or empty buffer
:tabnext
TabsGo to next tab
Syntax:
:tabnext
Examples:
:tabnext
Switch to next tabgt
Normal mode shortcut for next tabNotes:
gt is the normal mode equivalent
:tabprev
TabsGo to previous tab
Syntax:
:tabprev
Examples:
:tabprev
Switch to previous tabgT
Normal mode shortcut for previous tabNotes:
gT is the normal mode equivalent
:tabclose
TabsClose current tab
Syntax:
:tabclose
Examples:
:tabclose
Close current tabNotes:
Closes tab and its windows
:tabonly
TabsClose all other tabs
Syntax:
:tabonly
Examples:
:tabonly
Keep only current tabNotes:
Closes all tabs except current
v
Visual ModeEnter character-wise visual mode
Syntax:
v
Examples:
v
Start selecting charactersNotes:
Select individual characters
V
Visual ModeEnter line-wise visual mode
Syntax:
V
Examples:
V
Start selecting entire linesNotes:
Select complete lines
Ctrl+v
Visual ModeEnter block-wise visual mode
Syntax:
Ctrl+v
Examples:
Ctrl+v
Start selecting rectangular blocksNotes:
Select rectangular blocks of text
gv
Visual ModeRe-select last visual selection
Syntax:
gv
Examples:
gv
Restore previous visual selectionNotes:
Useful for re-applying operations
u
Undo & RedoUndo last change
Syntax:
u
Examples:
u
Undo last edit5u
Undo last 5 changesNotes:
Can be repeated with numbers
Ctrl+r
Undo & RedoRedo change
Syntax:
Ctrl+r
Examples:
Ctrl+r
Redo last undone changeNotes:
Opposite of undo
U
Undo & RedoUndo all changes to current line
Syntax:
U
Examples:
U
Restore line to original stateNotes:
Only works if you haven't moved away from line
"register
RegistersUse specific register
Syntax:
"[register][command]
Examples:
"ayy
Copy line to register 'a'"ap
Paste from register 'a'"0p
Paste from yank registerNotes:
Registers a-z, 0-9, and special registers
:registers
RegistersShow all registers
Syntax:
:registers [register]
Examples:
:registers
Show all register contents:registers a
Show register 'a' contentNotes:
Also available as :reg
m{letter}
MarksSet mark at current position
Syntax:
m[a-zA-Z]
Examples:
ma
Set mark 'a' at current positionmA
Set global mark 'A'Notes:
Lowercase marks are local to buffer, uppercase are global
'{letter}
MarksGo to mark
Syntax:
'[a-zA-Z]
Examples:
'a
Go to line with mark 'a'`a
Go to exact position of mark 'a'Notes:
' goes to line start, ` goes to exact position
:marks
MarksShow all marks
Syntax:
:marks [marks]
Examples:
:marks
Show all marks:marks abc
Show marks a, b, and cNotes:
Lists marks and their positions
q{letter}
MacrosStart recording macro
Syntax:
q[a-z]
Examples:
qa
Start recording macro into register 'a'Notes:
Press q again to stop recording
q
MacrosStop recording macro
Syntax:
q
Examples:
q
Stop current macro recordingNotes:
Only works when recording a macro
@{letter}
MacrosPlay macro
Syntax:
@[a-z]
Examples:
@a
Execute macro stored in register 'a'5@a
Execute macro 'a' 5 timesNotes:
Can be repeated with numbers
@@
MacrosRepeat last macro
Syntax:
@@
Examples:
@@
Repeat the last executed macroNotes:
Convenient for repeating macros
aw/iw
Text ObjectsWord text object
Syntax:
[operation][a/i]w
Examples:
daw
Delete a word (including surrounding whitespace)diw
Delete inner word (word only)caw
Change a wordNotes:
'a' includes surrounding, 'i' is inner only
as/is
Text ObjectsSentence text object
Syntax:
[operation][a/i]s
Examples:
das
Delete a sentencevis
Select inner sentenceNotes:
Sentence ends with ., !, or ?
ap/ip
Text ObjectsParagraph text object
Syntax:
[operation][a/i]p
Examples:
dap
Delete a paragraphvip
Select inner paragraphNotes:
Paragraph separated by blank lines
a)/i)
Text ObjectsParentheses text object
Syntax:
[operation][a/i])
Examples:
da)
Delete text including parenthesesdi)
Delete text inside parenthesesvi(
Select text inside parenthesesNotes:
Works with (, ), [, ], {, }, <, >
a'/i'
Text ObjectsQuote text object
Syntax:
[operation][a/i][quote]
Examples:
da'
Delete text including single quotesdi'
Delete text inside single quotesvi"
Select text inside double quotesNotes:
Works with ', ", and `
zf
FoldingCreate fold
Syntax:
zf[motion]
Examples:
zf5j
Fold 5 lines downzf%
Fold to matching bracketNotes:
Creates manual fold
zo
FoldingOpen fold under cursor
Syntax:
zo
Examples:
zo
Open fold at cursorNotes:
Opens one level of folding
zc
FoldingClose fold under cursor
Syntax:
zc
Examples:
zc
Close fold at cursorNotes:
Closes one level of folding
za
FoldingToggle fold under cursor
Syntax:
za
Examples:
za
Open if closed, close if openNotes:
Convenient for toggling folds
zR
FoldingOpen all folds
Syntax:
zR
Examples:
zR
Open all folds in bufferNotes:
Opens all levels of folding
zM
FoldingClose all folds
Syntax:
zM
Examples:
zM
Close all folds in bufferNotes:
Closes all levels of folding
VIM Editor Mastery Guide
VIM Modes
- Normal Mode: Default mode for navigation and commands
- Insert Mode: For typing text (enter with
i
,a
,o
) - Visual Mode: For selecting text (
v
,V
,Ctrl+v
) - Command Mode: For file operations (start with
:
) - Press
Esc
to return to Normal mode
Essential Workflow
vim filename
- Open filei
- Enter insert mode to edit- Type your content
Esc
- Return to normal mode:w
- Save file:q
- Quit (or:wq
to save and quit)
Quick Navigation
h j k l
- Left, down, up, rightw b e
- Word navigation^ $ 0
- Line navigationgg G
- File navigationf t
- Character search in line
Power Features
:split :vsplit
- Window management:tabnew gt gT
- Tab managementqa @a @@
- Macro recording/playbackma 'a `a
- Marks and jumps\"a
- Named registers
Text Objects
diw daw
- Delete inner/around worddi( da(
- Delete inside/around parenthesesdi\" da\"
- Delete inside/around quotesdip dap
- Delete inner/around paragraph- Combine with
c
(change) ory
(yank)
Visual Mode Power
v
- Character-wise selectionV
- Line-wise selectionCtrl+v
- Block-wise selectiongv
- Re-select last selection- Use with operators:
d y c
etc.
Search & Replace
/pattern
- Search forward?pattern
- Search backwardn N
- Next/previous match* #
- Search word under cursor:%s/old/new/g
- Replace all in file
Common Gotchas
- Always check which mode you're in
- Use
:q!
to force quit without saving - Remember
u
for undo,Ctrl+r
for redo - Practice hjkl navigation instead of arrow keys
- Learn text objects for efficient editing
🎯 Pro Tips
- Customize VIM with
~/.vimrc
configuration file - Use
.
to repeat the last command - Learn to think in "verb + noun" (operator + text object)
- Master a few commands deeply rather than memorizing everything
- Practice regularly - VIM proficiency comes with muscle memory