VIM Cheat Sheet
Master VIM with this comprehensive reference guide. Find commands, shortcuts, and examples with this cheat sheet.
📚 Practice what you've learned with our VIM Flashcards
h
NavigationMove cursor left
Syntax:
hExamples:
h Move one character to the left5h Move five characters to the leftNotes:
Basic cursor movement command
j
NavigationMove cursor down
Syntax:
jExamples:
j Move one line down10j Move ten lines downNotes:
Basic cursor movement command
k
NavigationMove cursor up
Syntax:
kExamples:
k Move one line up3k Move three lines upNotes:
Basic cursor movement command
l
NavigationMove cursor right
Syntax:
lExamples:
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:
wExamples:
w Move to next word3w Move forward 3 wordsNotes:
Stops at punctuation
W
NavigationMove to beginning of next WORD (whitespace separated)
Syntax:
WExamples:
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:
bExamples:
b Move to previous word2b Move back 2 wordsNotes:
Stops at punctuation
B
NavigationMove to beginning of previous WORD (whitespace separated)
Syntax:
BExamples:
B Move to previous whitespace-separated word3B Move back 3 WORDsNotes:
Ignores punctuation
e
NavigationMove to end of current word
Syntax:
eExamples:
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:
EExamples:
E Move to end of WORD2E Move to end of 2nd WORD aheadNotes:
Ignores punctuation
0
NavigationMove to beginning of line
Syntax:
0Examples:
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:
ggExamples:
gg Go to beginning of file5gg Go to line 5Notes:
Quick way to navigate to top
G
NavigationGo to last line of file
Syntax:
GExamples:
G Go to end of file10G Go to line 10Notes:
Quick way to navigate to bottom
Ctrl+u
NavigationScroll up half page
Syntax:
Ctrl+uExamples:
Ctrl+u Move half page upNotes:
Half page scroll
Ctrl+d
NavigationScroll down half page
Syntax:
Ctrl+dExamples:
Ctrl+d Move half page downNotes:
Half page scroll
Ctrl+f
NavigationPage down
Syntax:
Ctrl+fExamples:
Ctrl+f Move one page downNotes:
Full page scroll
Ctrl+b
NavigationPage up
Syntax:
Ctrl+bExamples:
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:
iExamples:
i Enter insert mode before cursorNotes:
Most common way to start editing
I
Insert ModeInsert at beginning of line
Syntax:
IExamples:
I Move to start of line and enter insert modeNotes:
Equivalent to ^i
a
Insert ModeInsert after cursor
Syntax:
aExamples:
a Enter insert mode after cursorNotes:
Useful for appending
A
Insert ModeInsert at end of line
Syntax:
AExamples:
A Move to end of line and enter insert modeNotes:
Equivalent to $a
o
Insert ModeOpen new line below
Syntax:
oExamples:
o Create new line below and enter insert modeNotes:
Creates line and enters insert mode
O
Insert ModeOpen new line above
Syntax:
OExamples:
O Create new line above and enter insert modeNotes:
Creates line and enters insert mode
s
Insert ModeSubstitute character
Syntax:
sExamples:
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:
SExamples:
S Delete entire line and enter insert modeNotes:
Equivalent to cc
x
DeleteDelete character under cursor
Syntax:
xExamples:
x Delete current character5x Delete 5 charactersNotes:
Like pressing Delete key
X
DeleteDelete character before cursor
Syntax:
XExamples:
X Delete character to the left3X Delete 3 characters to the leftNotes:
Like pressing Backspace
dd
DeleteDelete entire line
Syntax:
ddExamples:
dd Delete current line3dd Delete 3 lines starting from currentNotes:
Line goes to default register
dw
DeleteDelete word
Syntax:
dwExamples:
dw Delete from cursor to end of word2dw Delete 2 wordsNotes:
Includes trailing whitespace
de
DeleteDelete to end of word
Syntax:
deExamples:
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:
d0Examples:
d0 Delete from cursor to start of lineNotes:
Doesn't delete the character under cursor
dgg
DeleteDelete to beginning of file
Syntax:
dggExamples:
dgg Delete from cursor to start of fileNotes:
Deletes all lines above and current line
dG
DeleteDelete to end of file
Syntax:
dGExamples:
dG Delete from cursor to end of fileNotes:
Deletes current line and all lines below
yy
CopyYank (copy) entire line
Syntax:
yyExamples:
yy Copy current line3yy Copy 3 lines starting from currentNotes:
Line goes to default register
yw
CopyYank word
Syntax:
ywExamples:
yw Copy word from cursor2yw Copy 2 wordsNotes:
Includes trailing whitespace
ye
CopyYank to end of word
Syntax:
yeExamples:
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:
y0Examples:
y0 Copy from cursor to start of lineNotes:
Doesn't include character under cursor
ygg
CopyYank to beginning of file
Syntax:
yggExamples:
ygg Copy from cursor to start of fileNotes:
Copies all lines above and current line
yG
CopyYank to end of file
Syntax:
yGExamples:
yG Copy from cursor to end of fileNotes:
Copies current line and all lines below
p
PastePaste after cursor
Syntax:
pExamples:
p Paste after cursor or below current line3p Paste 3 timesNotes:
Paste location depends on what was copied
P
PastePaste before cursor
Syntax:
PExamples:
P Paste before cursor or above current lineNotes:
Opposite of p
cc
ChangeChange entire line
Syntax:
ccExamples:
cc Delete line and enter insert mode2cc Change 2 linesNotes:
Equivalent to S
cw
ChangeChange word
Syntax:
cwExamples:
cw Delete word and enter insert mode3cw Change 3 wordsNotes:
Delete and insert in one command
ce
ChangeChange to end of word
Syntax:
ceExamples:
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:
c0Examples:
c0 Delete to start of line and enter insert modeNotes:
Doesn't delete character under cursor
/pattern
SearchSearch forward for pattern
Syntax:
/patternExamples:
/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:
?patternExamples:
?hello Search for 'hello' going backward?function Search for 'function' backwardNotes:
Use Enter to execute search
n
SearchNext search result
Syntax:
nExamples:
n Go to next match in same directionNotes:
Repeats last search in same direction
N
SearchPrevious search result
Syntax:
NExamples:
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:
:wqExamples:
: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 wExamples:
Ctrl+w w Move to next windowNotes:
Cycles through all windows
Ctrl+w h
WindowsMove to left window
Syntax:
Ctrl+w hExamples:
Ctrl+w h Move to window on the leftNotes:
Directional window navigation
Ctrl+w j
WindowsMove to window below
Syntax:
Ctrl+w jExamples:
Ctrl+w j Move to window belowNotes:
Directional window navigation
Ctrl+w k
WindowsMove to window above
Syntax:
Ctrl+w kExamples:
Ctrl+w k Move to window aboveNotes:
Directional window navigation
Ctrl+w l
WindowsMove to right window
Syntax:
Ctrl+w lExamples:
Ctrl+w l Move to window on the rightNotes:
Directional window navigation
Ctrl+w q
WindowsClose current window
Syntax:
Ctrl+w qExamples:
Ctrl+w q Close current windowNotes:
Equivalent to :q
Ctrl+w o
WindowsClose all other windows
Syntax:
Ctrl+w oExamples:
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:
:tabnextExamples:
:tabnext Switch to next tabgt Normal mode shortcut for next tabNotes:
gt is the normal mode equivalent
:tabprev
TabsGo to previous tab
Syntax:
:tabprevExamples:
:tabprev Switch to previous tabgT Normal mode shortcut for previous tabNotes:
gT is the normal mode equivalent
:tabclose
TabsClose current tab
Syntax:
:tabcloseExamples:
:tabclose Close current tabNotes:
Closes tab and its windows
:tabonly
TabsClose all other tabs
Syntax:
:tabonlyExamples:
:tabonly Keep only current tabNotes:
Closes all tabs except current
v
Visual ModeEnter character-wise visual mode
Syntax:
vExamples:
v Start selecting charactersNotes:
Select individual characters
V
Visual ModeEnter line-wise visual mode
Syntax:
VExamples:
V Start selecting entire linesNotes:
Select complete lines
Ctrl+v
Visual ModeEnter block-wise visual mode
Syntax:
Ctrl+vExamples:
Ctrl+v Start selecting rectangular blocksNotes:
Select rectangular blocks of text
gv
Visual ModeRe-select last visual selection
Syntax:
gvExamples:
gv Restore previous visual selectionNotes:
Useful for re-applying operations
u
Undo & RedoUndo last change
Syntax:
uExamples:
u Undo last edit5u Undo last 5 changesNotes:
Can be repeated with numbers
Ctrl+r
Undo & RedoRedo change
Syntax:
Ctrl+rExamples:
Ctrl+r Redo last undone changeNotes:
Opposite of undo
U
Undo & RedoUndo all changes to current line
Syntax:
UExamples:
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:
qExamples:
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]wExamples:
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]sExamples:
das Delete a sentencevis Select inner sentenceNotes:
Sentence ends with ., !, or ?
ap/ip
Text ObjectsParagraph text object
Syntax:
[operation][a/i]pExamples:
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:
zoExamples:
zo Open fold at cursorNotes:
Opens one level of folding
zc
FoldingClose fold under cursor
Syntax:
zcExamples:
zc Close fold at cursorNotes:
Closes one level of folding
za
FoldingToggle fold under cursor
Syntax:
zaExamples:
za Open if closed, close if openNotes:
Convenient for toggling folds
zR
FoldingOpen all folds
Syntax:
zRExamples:
zR Open all folds in bufferNotes:
Opens all levels of folding
zM
FoldingClose all folds
Syntax:
zMExamples:
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
Escto 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:wqto 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 cetc.
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
ufor undo,Ctrl+rfor redo - Practice hjkl navigation instead of arrow keys
- Learn text objects for efficient editing
🎯 Pro Tips
- Customize VIM with
~/.vimrcconfiguration 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
📚 What is Vim?
Vim (Vi Improved) is a highly configurable, powerful text editor built to make creating and changing text very efficient. It's an enhanced version of the vi editor that comes with most Unix systems. Originally created by Bram Moolenaar in 1991, Vim has become one of the most popular text editors among programmers, system administrators, and power users worldwide.
🚀 Key Features
- ✓ Modal editing: Different modes for different tasks (normal, insert, visual, command)
- ✓ Highly efficient: Minimal mouse usage, keyboard-driven workflow
- ✓ Extensible: Thousands of plugins and customization options
- ✓ Cross-platform: Available on virtually every operating system
- ✓ Lightweight: Fast startup and low resource usage
- ✓ Powerful search & replace: Regular expressions and advanced text manipulation
💡 Why Choose Vim?
- • Speed: Once mastered, editing becomes incredibly fast
- • Ubiquity: Available on servers, embedded systems, and all platforms
- • Consistency: Same interface everywhere, no matter the environment
- • Powerful: Handle large files and complex editing tasks efficiently
- • Free & Open Source: No licensing costs, community-driven development
- • Career value: Highly valued skill in tech industry
🎯 Who Uses Vim?
Software Developers
For coding in any programming language with powerful text manipulation and plugin ecosystem
System Administrators
For editing configuration files, scripts, and logs on servers without GUI
Writers & Content Creators
For distraction-free writing, markdown editing, and document processing
🚀 Getting Started with Vim
1. Installation
sudo apt install vim (Ubuntu/Debian) • brew install vim (macOS) •
Pre-installed on most Linux/Unix systems
2. Learn the Basics
Start with vimtutor command for interactive tutorial • Practice modal editing • Master basic navigation
3. Build Muscle Memory
Use Vim daily for small tasks • Focus on efficiency over speed initially • Gradually learn advanced features
Remember: Vim has a steep learning curve, but the investment pays off with dramatically increased editing efficiency. Start with the basics and gradually build your skillset. This cheat sheet is your companion on that journey! 🎯