Vim Cheatsheet

This cheatsheet provides a comprehensive and practical reference for Vim commands, modes, and operations. Use it to quickly look up and learn essential Vim commands.

Vim Cheatsheet

Complete Vim commands and shortcuts reference

546

Commands

16

Categories

0

Favorites

71

Sections

Getting Started
Exiting Vim
:qClose file (quit)
:q!Quit without saving (force)
:qaClose all files
:qa!Close all without saving
:wSave (write)
:w filenameSave as filename
:wqSave and quit
:xSave and quit (only if changed)
ZZSave and quit (normal mode)
ZQQuit without saving (normal mode)
Getting Started
Opening Files
:e filenameEdit a file
:e!Reload current file (discard changes)
:e .Open file explorer
:enewEdit new unnamed buffer
:r filenameInsert file content below cursor
:r !commandInsert command output
Getting Started
Exit Insert Mode
EscExit insert mode
Ctrl+[Exit insert mode (alternative)
Ctrl+CExit insert mode, abort command
jj / jkCommon custom mappings

💡 Many users remap jj or jk to Esc for faster exit

Editing
Entering Insert Mode
iInsert before cursor
IInsert at beginning of line
aAppend after cursor
AAppend at end of line
oOpen new line below
OOpen new line above
giInsert at last insert position
gIInsert at column 1
Editing
Change (Delete + Insert)
sDelete char and insert
SDelete line and insert
CDelete to end of line and insert
ccChange entire line
cwChange word
ciwChange inner word
ci"Change inside quotes
ci(Change inside parentheses
ci{Change inside braces
citChange inside tag
c$Change to end of line
c0Change to start of line
Editing
Replace
rReplace single character
REnter Replace mode
~Toggle case of character
g~wToggle case of word
gUwUppercase word
guwLowercase word
gUUUppercase entire line
guuLowercase entire line
Editing
Delete
xDelete character under cursor
XDelete character before cursor
ddDelete entire line
DDelete to end of line
dwDelete word
diwDelete inner word
dawDelete a word (with space)
di"Delete inside quotes
da"Delete around quotes
dipDelete inner paragraph
d$Delete to end of line
d0Delete to start of line
dGDelete to end of file
dggDelete to start of file
Editing
Clipboard (Yank/Paste)
yyYank (copy) line
YYank line (same as yy)
ywYank word
yiwYank inner word
yi"Yank inside quotes
y$Yank to end of line
pPaste after cursor
PPaste before cursor
gpPaste and move cursor after
gPPaste before and move cursor after
"+yYank to system clipboard
"+pPaste from system clipboard
"0pPaste from yank register

💡 Use "+ register for system clipboard

Editing
Undo & Redo
uUndo
UUndo all changes on line
Ctrl+RRedo
.Repeat last change
:earlier 5mGo back 5 minutes
:later 5mGo forward 5 minutes
g-Go to older text state
g+Go to newer text state
Navigation
Basic Movement
hMove left
jMove down
kMove up
lMove right
gjMove down (display line)
gkMove up (display line)
Navigation
Word Movement
wNext word start
WNext WORD start (space-separated)
eNext word end
ENext WORD end
bPrevious word start
BPrevious WORD start
gePrevious word end
gEPrevious WORD end

💡 WORD = sequence of non-blank characters

Navigation
Line Movement
0Start of line
^First non-blank character
$End of line
g_Last non-blank character
|Go to column 1
n|Go to column n
+First non-blank of next line
-First non-blank of previous line
Navigation
Screen Movement
Ctrl+FPage down (forward)
Ctrl+BPage up (backward)
Ctrl+DHalf page down
Ctrl+UHalf page up
Ctrl+EScroll down one line
Ctrl+YScroll up one line
HMove to top of screen
MMove to middle of screen
LMove to bottom of screen
ztScroll cursor to top
zzScroll cursor to center
zbScroll cursor to bottom
Navigation
Document Movement
ggGo to first line
GGo to last line
nGGo to line n
:nGo to line n
n%Go to n% of file
Ctrl+GShow file info and position
g Ctrl+GShow detailed position info
Navigation
Character Search
f{char}Find char forward
F{char}Find char backward
t{char}Till char forward
T{char}Till char backward
;Repeat last f/F/t/T
,Repeat last f/F/t/T reversed

💡 f lands on char, t lands before char

Navigation
Matching & Jumping
%Jump to matching bracket
[[Previous section/function
]]Next section/function
[{Previous unmatched {
]}Next unmatched }
[(Previous unmatched (
])Next unmatched )
[mPrevious method start
]mNext method start
Search & Replace
Search
/patternSearch forward
?patternSearch backward
nNext match
NPrevious match
*Search word under cursor forward
#Search word under cursor backward
g*Search partial word forward
g#Search partial word backward
/\cCase insensitive search
/\CCase sensitive search
:nohClear search highlighting
Search & Replace
Search Patterns
/\<word\>Exact word match
/^patternPattern at line start
/pattern$Pattern at line end
/pat1\|pat2Match pat1 OR pat2
/pat.*ternMatch with wildcard
/[abc]Match any of a, b, c
/[^abc]Match except a, b, c
/\dMatch digit
/\wMatch word character
/\sMatch whitespace

💡 Vim uses its own regex flavor

Search & Replace
Replace (Substitute)
:s/old/new/Replace first on line
:s/old/new/gReplace all on line
:%s/old/new/gReplace all in file
:%s/old/new/gcReplace all with confirm
:%s/old/new/giReplace case insensitive
:5,10s/old/new/gReplace in lines 5-10
:'<,'>s/old/new/gReplace in selection
:%s/\s\+$//Remove trailing whitespace
:%s/^/prefix/Add prefix to all lines
:%s/$/suffix/Add suffix to all lines
Search & Replace
Replace Special
&Matched pattern in replacement
\1, \2Captured groups
\rNewline in replacement
\tTab in replacement
\uUppercase next char
\UUppercase until \E
\lLowercase next char
\LLowercase until \E

💡 Use \( \) for capture groups

Operators
Operator List
dDelete
cChange (delete + insert)
yYank (copy)
>Indent right
<Indent left
=Auto-indent
g~Toggle case
gUUppercase
guLowercase
!Filter through external command
gqFormat text

💡 Operators work with motions: operator + motion

Operators
Operator + Motion Examples
dwDelete word
d2wDelete 2 words
d$Delete to end of line
d0Delete to start of line
dGDelete to end of file
dggDelete to start of file
df)Delete to and including )
dt)Delete until )
d/patternDelete to pattern
y3jYank 3 lines down
>}Indent to end of paragraph
=apAuto-indent paragraph
Operators
Double Operator (Line)
ddDelete line
ccChange line
yyYank line
>>Indent line
<<Unindent line
==Auto-indent line
gUUUppercase line
guuLowercase line
g~~Toggle case line

💡 Double operator = apply to current line

Operators
Count + Operator
3ddDelete 3 lines
5yyYank 5 lines
2>>Indent 2 lines
d3wDelete 3 words
c2f)Change to 2nd )
y5jYank 5 lines down
Text Objects
Inner vs Around
iInner (inside, excluding delimiters)
aAround (including delimiters)

💡 Use with operators: d + i/a + object

Text Objects
Word Objects
iwInner word
awA word (with trailing space)
iWInner WORD
aWA WORD (with trailing space)
Text Objects
Sentence & Paragraph
isInner sentence
asA sentence
ipInner paragraph
apA paragraph
Text Objects
Block Objects
i( / i)Inside parentheses
a( / a)Around parentheses
i[ / i]Inside brackets
a[ / a]Around brackets
i{ / i}Inside braces
a{ / a}Around braces
i< / i>Inside angle brackets
a< / a>Around angle brackets
ibInside block (same as i()
aBAround Block (same as a{)
Text Objects
Quote Objects
i"Inside double quotes
a"Around double quotes
i'Inside single quotes
a'Around single quotes
i`Inside backticks
a`Around backticks
Text Objects
Tag Objects
itInside tag
atAround tag

💡 Works with HTML/XML tags

Text Objects
Text Object Examples
diwDelete inner word
dawDelete a word
ci"Change inside quotes
ca"Change around quotes
yi{Yank inside braces
vipSelect inner paragraph
ditDelete inside tag
>ipIndent inner paragraph
Visual Mode
Enter Visual Mode
vCharacter-wise visual
VLine-wise visual
Ctrl+VBlock-wise visual
gvReselect last selection
oMove to other end of selection
OMove to other corner (block)
Visual Mode
Visual Mode Actions
d / xDelete selection
yYank selection
cChange selection
r{char}Replace with character
>Indent selection
<Unindent selection
=Auto-indent selection
~Toggle case
UUppercase
uLowercase
JJoin lines
gJJoin lines without space
:Command on selection
EscExit visual mode
Visual Mode
Block Visual Special
IInsert at start of each line
AAppend at end of each line
cChange each line
$Extend to end of lines

💡 Block mode allows multi-line editing

Visual Mode
Expand Selection
awExpand to word
abExpand to () block
aBExpand to {} block
atExpand to tag
apExpand to paragraph
Windows & Tabs
Window Splits
:sp [file]Horizontal split
:vsp [file]Vertical split
:newNew horizontal split
:vnewNew vertical split
Ctrl+W sSplit horizontally
Ctrl+W vSplit vertically
Ctrl+W nNew window
Windows & Tabs
Window Navigation
Ctrl+W wCycle through windows
Ctrl+W hGo to left window
Ctrl+W jGo to window below
Ctrl+W kGo to window above
Ctrl+W lGo to right window
Ctrl+W pGo to previous window
Ctrl+W tGo to top-left window
Ctrl+W bGo to bottom-right window
Windows & Tabs
Window Management
Ctrl+W qClose window
Ctrl+W cClose window (keep buffer)
Ctrl+W oClose all other windows
Ctrl+W =Equal size windows
Ctrl+W _Maximize height
Ctrl+W |Maximize width
Ctrl+W +Increase height
Ctrl+W -Decrease height
Ctrl+W >Increase width
Ctrl+W <Decrease width
Ctrl+W rRotate windows down
Ctrl+W RRotate windows up
Ctrl+W xExchange with next window
Windows & Tabs
Window Moving
Ctrl+W HMove window to far left
Ctrl+W JMove window to bottom
Ctrl+W KMove window to top
Ctrl+W LMove window to far right
Ctrl+W TMove window to new tab
Windows & Tabs
Tab Pages
:tabnew [file]Open new tab
:tabe [file]Edit file in new tab
:tabcloseClose current tab
:tabonlyClose all other tabs
gtGo to next tab
gTGo to previous tab
ngtGo to tab n
:tabsList all tabs
:tabm nMove tab to position n
:tabm +1Move tab right
:tabm -1Move tab left
Windows & Tabs
Buffers
:lsList buffers
:b nGo to buffer n
:bnNext buffer
:bpPrevious buffer
:bdDelete buffer
:b nameGo to buffer by name
:bufdo cmdRun command on all buffers
Marks & Jumps
Setting Marks
maSet mark 'a' at cursor
mASet global mark 'A'
:marksList all marks
:delmarks aDelete mark 'a'
:delmarks!Delete all lowercase marks

💡 a-z local marks, A-Z global marks

Marks & Jumps
Jumping to Marks
'aJump to line of mark 'a'
`aJump to position of mark 'a'
''Jump to last jump position
``Jump to exact last position
'.Jump to last change
'"Jump to position when last edited
'[Start of last change/yank
']End of last change/yank
'<Start of last visual selection
'>End of last visual selection
Marks & Jumps
Jump List
Ctrl+OGo to older position
Ctrl+IGo to newer position
:jumpsList jump history
:clearjumpsClear jump list
Marks & Jumps
Change List
g;Go to older change
g,Go to newer change
:changesList change history
Macros
Recording Macros
qaStart recording macro 'a'
qStop recording
@aRun macro 'a'
@@Repeat last macro
5@aRun macro 'a' 5 times
:reg aView macro 'a' content

💡 Macros are stored in registers a-z

Macros
Editing Macros
"apPaste macro 'a' content
"ay$Yank line into macro 'a'
:let @a='...'Set macro content
:let @A='...'Append to macro 'a'
Macros
Running on Multiple Lines
:5,10norm @aRun macro on lines 5-10
:%norm @aRun macro on all lines
:'<,'>norm @aRun macro on selection
:g/pattern/norm @aRun on matching lines
Registers
Register Types
""Unnamed register (default)
"0Yank register
"1-9Delete registers (history)
"a-zNamed registers
"A-ZAppend to named register
"+System clipboard
"*Selection clipboard (X11)
"_Black hole register
"/Last search pattern
":Last command
".Last inserted text
"%Current filename
"#Alternate filename
"=Expression register
Registers
Using Registers
:regShow all registers
:reg aShow register 'a'
"ayYank into register 'a'
"apPaste from register 'a'
"AyAppend yank to register 'a'
"_dDelete without saving
"+pPaste from clipboard
"+yYank to clipboard
Ctrl+R aInsert register 'a' (insert mode)
Folds
Fold Commands
zoOpen fold under cursor
zOOpen all folds under cursor
zcClose fold under cursor
zCClose all folds under cursor
zaToggle fold
zAToggle all folds under cursor
zvOpen folds to show cursor line
zMClose all folds
zROpen all folds
zmFold more (increase foldlevel)
zrFold less (decrease foldlevel)
Folds
Creating Folds
zf{motion}Create fold
zf'aFold to mark 'a'
:n,mfoldFold lines n to m
zdDelete fold under cursor
zDDelete all folds under cursor
zEDelete all folds in file
Folds
Fold Navigation
zjMove to next fold
zkMove to previous fold
[zMove to start of open fold
]zMove to end of open fold
Folds
Fold Methods
:set foldmethod=manualManual folding
:set foldmethod=indentFold by indent
:set foldmethod=syntaxFold by syntax
:set foldmethod=markerFold by markers
:set foldmethod=exprFold by expression
:set foldmethod=diffFold unchanged text
Insert Mode
Insert Mode Commands
Ctrl+HDelete character before cursor
Ctrl+WDelete word before cursor
Ctrl+UDelete to start of line
Ctrl+TIndent line
Ctrl+DUnindent line
Ctrl+JInsert newline
Ctrl+MInsert newline
Insert Mode
Insert Special
Ctrl+R aInsert register 'a'
Ctrl+R "Insert unnamed register
Ctrl+R +Insert clipboard
Ctrl+R =Insert expression result
Ctrl+R /Insert last search
Ctrl+AInsert last inserted text
Ctrl+@Insert last inserted and exit
Ctrl+OExecute one normal command
Ctrl+VInsert literal character
Ctrl+V u1234Insert unicode character
Insert Mode
Completion
Ctrl+NNext completion
Ctrl+PPrevious completion
Ctrl+X Ctrl+FFilename completion
Ctrl+X Ctrl+LLine completion
Ctrl+X Ctrl+OOmni completion
Ctrl+X Ctrl+KDictionary completion
Ctrl+X Ctrl+]Tag completion
Command Line
Command Line Basics
:Enter command mode
:!Execute shell command
:!!Repeat last shell command
:r !cmdInsert command output
:w !cmdSend buffer to command
:%!cmdFilter buffer through command
:shOpen shell
Ctrl+ZSuspend Vim
Command Line
Command History
q:Open command history window
q/Open search history window
Ctrl+FEdit command in window
↑ / ↓Navigate command history
:historyShow command history
Command Line
Ranges
.Current line
$Last line
%All lines (same as 1,$)
nLine number n
n,mLines n to m
'a,'bFrom mark a to mark b
'<,'>Visual selection
/pat1/,/pat2/Pattern range
.+33 lines after current
.-33 lines before current
Command Line
Global Command
:g/pattern/cmdRun cmd on matching lines
:g!/pattern/cmdRun cmd on non-matching
:v/pattern/cmdSame as :g!
:g/pattern/dDelete matching lines
:g/^$/dDelete empty lines
:g/pattern/y AYank matches to register
:g/pattern/m$Move matches to end
Settings
Common Settings
:set numberShow line numbers
:set relativenumberRelative line numbers
:set nonumberHide line numbers
:set wrapWrap long lines
:set nowrapDon't wrap lines
:set listShow invisible characters
:set nolistHide invisible characters
:set cursorlineHighlight current line
:set hlsearchHighlight search results
:set incsearchIncremental search
:set ignorecaseCase insensitive search
:set smartcaseSmart case search
Settings
Indentation
:set tabstop=4Tab width
:set shiftwidth=4Indent width
:set expandtabUse spaces instead of tabs
:set autoindentAuto indent new lines
:set smartindentSmart auto indent
:retabConvert tabs to spaces
Settings
File Settings
:set encoding=utf-8Set encoding
:set fileformat=unixUnix line endings
:set fileformat=dosWindows line endings
:set autoreadAuto reload changed files
:set hiddenAllow hidden buffers
:set backupCreate backup files
:set noswapfileDisable swap files
Settings
Toggle Settings
:set option!Toggle boolean option
:set option?Show option value
:set option&Reset to default
:setlocal optionSet for current buffer
Advanced
Spell Checking
:set spellEnable spell check
:set spelllang=enSet spell language
]sNext misspelled word
[sPrevious misspelled word
z=Suggest corrections
zgAdd word to dictionary
zwMark word as wrong
zugUndo add to dictionary
Advanced
Diff Mode
:diffsplit fileDiff with file
:diffthisMake current window diff
:diffoffTurn off diff mode
:diffupdateUpdate diff
doObtain diff from other
dpPut diff to other
]cNext difference
[cPrevious difference
Advanced
Sessions
:mksession file.vimSave session
:source file.vimLoad session
vim -S file.vimStart with session
Advanced
Quickfix
:makeRun make and populate quickfix
:copenOpen quickfix window
:ccloseClose quickfix window
:cnNext quickfix item
:cpPrevious quickfix item
:cfirstFirst quickfix item
:clastLast quickfix item
:cdo cmdRun cmd on each quickfix item
Advanced
Tags
Ctrl+]Jump to tag definition
Ctrl+TJump back from tag
:tag nameJump to tag
:tagsShow tag stack
:tselectSelect from multiple tags
g]List matching tags
g Ctrl+]Jump or list tags
Advanced
Miscellaneous
gaShow ASCII value of char
g8Show UTF-8 bytes of char
gfGo to file under cursor
gxOpen URL under cursor
Ctrl+AIncrement number
Ctrl+XDecrement number
g Ctrl+AIncrement sequence (visual)
:!sortSort selected lines
:sortSort lines
:sort!Sort reverse
:sort uSort unique

Vim Modes Quick Reference

Normal

Default mode for navigation and commands

Esc

Insert

For typing and editing text

i, a, o, I, A, O

Visual

For selecting text

v, V, Ctrl+V

Command

For Ex commands

:

Pro Tips

Use . to repeat the last change - one of Vim's most powerful features

Combine operators with text objects: ci" changes inside quotes

Use * to search for the word under cursor instantly

Record macros with q{a-z} for repetitive tasks

Categories

  • Basic Movement

    Essential cursor movement commands for navigation.

  • Insert Mode

    Commands for entering and exiting insert mode.

  • Editing

    Text manipulation, deletion, and modification commands.

  • Search & Replace

    Pattern searching and text replacement operations.

  • Visual Mode

    Text selection and manipulation in visual mode.

  • File Operations

    File saving, loading, and window management.

  • Advanced

    Advanced features like marks, windows, and navigation.

Features

  • Quick search functionality
  • Organized by categories
  • Mode-specific commands
  • Common and advanced operations
  • Clear command descriptions
  • Responsive design
  • Perfect for quick reference