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
Commands
Categories
Favorites
Sections
: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):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 outputEscExit insert modeCtrl+[Exit insert mode (alternative)Ctrl+CExit insert mode, abort commandjj / jkCommon custom mappings💡 Many users remap jj or jk to Esc for faster exit
iInsert before cursorIInsert at beginning of lineaAppend after cursorAAppend at end of lineoOpen new line belowOOpen new line abovegiInsert at last insert positiongIInsert at column 1sDelete char and insertSDelete line and insertCDelete to end of line and insertccChange entire linecwChange wordciwChange inner wordci"Change inside quotesci(Change inside parenthesesci{Change inside bracescitChange inside tagc$Change to end of linec0Change to start of linerReplace single characterREnter Replace mode~Toggle case of characterg~wToggle case of wordgUwUppercase wordguwLowercase wordgUUUppercase entire lineguuLowercase entire linexDelete character under cursorXDelete character before cursorddDelete entire lineDDelete to end of linedwDelete worddiwDelete inner worddawDelete a word (with space)di"Delete inside quotesda"Delete around quotesdipDelete inner paragraphd$Delete to end of lined0Delete to start of linedGDelete to end of filedggDelete to start of fileyyYank (copy) lineYYank line (same as yy)ywYank wordyiwYank inner wordyi"Yank inside quotesy$Yank to end of linepPaste after cursorPPaste before cursorgpPaste and move cursor aftergPPaste before and move cursor after"+yYank to system clipboard"+pPaste from system clipboard"0pPaste from yank register💡 Use "+ register for system clipboard
uUndoUUndo all changes on lineCtrl+RRedo.Repeat last change:earlier 5mGo back 5 minutes:later 5mGo forward 5 minutesg-Go to older text stateg+Go to newer text statehMove leftjMove downkMove uplMove rightgjMove down (display line)gkMove up (display line)wNext word startWNext WORD start (space-separated)eNext word endENext WORD endbPrevious word startBPrevious WORD startgePrevious word endgEPrevious WORD end💡 WORD = sequence of non-blank characters
0Start of line^First non-blank character$End of lineg_Last non-blank character|Go to column 1n|Go to column n+First non-blank of next line-First non-blank of previous lineCtrl+FPage down (forward)Ctrl+BPage up (backward)Ctrl+DHalf page downCtrl+UHalf page upCtrl+EScroll down one lineCtrl+YScroll up one lineHMove to top of screenMMove to middle of screenLMove to bottom of screenztScroll cursor to topzzScroll cursor to centerzbScroll cursor to bottomggGo to first lineGGo to last linenGGo to line n:nGo to line nn%Go to n% of fileCtrl+GShow file info and positiong Ctrl+GShow detailed position infof{char}Find char forwardF{char}Find char backwardt{char}Till char forwardT{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
%Jump to matching bracket[[Previous section/function]]Next section/function[{Previous unmatched {]}Next unmatched }[(Previous unmatched (])Next unmatched )[mPrevious method start]mNext method start/patternSearch forward?patternSearch backwardnNext matchNPrevious match*Search word under cursor forward#Search word under cursor backwardg*Search partial word forwardg#Search partial word backward/\cCase insensitive search/\CCase sensitive search:nohClear search highlighting/\<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
: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&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
dDeletecChange (delete + insert)yYank (copy)>Indent right<Indent left=Auto-indentg~Toggle casegUUppercaseguLowercase!Filter through external commandgqFormat text💡 Operators work with motions: operator + motion
dwDelete wordd2wDelete 2 wordsd$Delete to end of lined0Delete to start of linedGDelete to end of filedggDelete to start of filedf)Delete to and including )dt)Delete until )d/patternDelete to patterny3jYank 3 lines down>}Indent to end of paragraph=apAuto-indent paragraphddDelete lineccChange lineyyYank line>>Indent line<<Unindent line==Auto-indent linegUUUppercase lineguuLowercase lineg~~Toggle case line💡 Double operator = apply to current line
3ddDelete 3 lines5yyYank 5 lines2>>Indent 2 linesd3wDelete 3 wordsc2f)Change to 2nd )y5jYank 5 lines downiInner (inside, excluding delimiters)aAround (including delimiters)💡 Use with operators: d + i/a + object
iwInner wordawA word (with trailing space)iWInner WORDaWA WORD (with trailing space)isInner sentenceasA sentenceipInner paragraphapA paragraphi( / i)Inside parenthesesa( / a)Around parenthesesi[ / i]Inside bracketsa[ / a]Around bracketsi{ / i}Inside bracesa{ / a}Around bracesi< / i>Inside angle bracketsa< / a>Around angle bracketsibInside block (same as i()aBAround Block (same as a{)i"Inside double quotesa"Around double quotesi'Inside single quotesa'Around single quotesi`Inside backticksa`Around backticksitInside tagatAround tag💡 Works with HTML/XML tags
diwDelete inner worddawDelete a wordci"Change inside quotesca"Change around quotesyi{Yank inside bracesvipSelect inner paragraphditDelete inside tag>ipIndent inner paragraphvCharacter-wise visualVLine-wise visualCtrl+VBlock-wise visualgvReselect last selectionoMove to other end of selectionOMove to other corner (block)d / xDelete selectionyYank selectioncChange selectionr{char}Replace with character>Indent selection<Unindent selection=Auto-indent selection~Toggle caseUUppercaseuLowercaseJJoin linesgJJoin lines without space:Command on selectionEscExit visual modeIInsert at start of each lineAAppend at end of each linecChange each line$Extend to end of lines💡 Block mode allows multi-line editing
awExpand to wordabExpand to () blockaBExpand to {} blockatExpand to tagapExpand to paragraph:sp [file]Horizontal split:vsp [file]Vertical split:newNew horizontal split:vnewNew vertical splitCtrl+W sSplit horizontallyCtrl+W vSplit verticallyCtrl+W nNew windowCtrl+W wCycle through windowsCtrl+W hGo to left windowCtrl+W jGo to window belowCtrl+W kGo to window aboveCtrl+W lGo to right windowCtrl+W pGo to previous windowCtrl+W tGo to top-left windowCtrl+W bGo to bottom-right windowCtrl+W qClose windowCtrl+W cClose window (keep buffer)Ctrl+W oClose all other windowsCtrl+W =Equal size windowsCtrl+W _Maximize heightCtrl+W |Maximize widthCtrl+W +Increase heightCtrl+W -Decrease heightCtrl+W >Increase widthCtrl+W <Decrease widthCtrl+W rRotate windows downCtrl+W RRotate windows upCtrl+W xExchange with next windowCtrl+W HMove window to far leftCtrl+W JMove window to bottomCtrl+W KMove window to topCtrl+W LMove window to far rightCtrl+W TMove window to new tab:tabnew [file]Open new tab:tabe [file]Edit file in new tab:tabcloseClose current tab:tabonlyClose all other tabsgtGo to next tabgTGo to previous tabngtGo to tab n:tabsList all tabs:tabm nMove tab to position n:tabm +1Move tab right:tabm -1Move tab left:lsList buffers:b nGo to buffer n:bnNext buffer:bpPrevious buffer:bdDelete buffer:b nameGo to buffer by name:bufdo cmdRun command on all buffersmaSet mark 'a' at cursormASet global mark 'A':marksList all marks:delmarks aDelete mark 'a':delmarks!Delete all lowercase marks💡 a-z local marks, A-Z global 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 selectionCtrl+OGo to older positionCtrl+IGo to newer position:jumpsList jump history:clearjumpsClear jump listg;Go to older changeg,Go to newer change:changesList change historyqaStart recording macro 'a'qStop recording@aRun macro 'a'@@Repeat last macro5@aRun macro 'a' 5 times:reg aView macro 'a' content💡 Macros are stored in registers a-z
"apPaste macro 'a' content"ay$Yank line into macro 'a':let @a='...'Set macro content:let @A='...'Append to macro 'a':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""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: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 clipboardCtrl+R aInsert register 'a' (insert mode)zoOpen fold under cursorzOOpen all folds under cursorzcClose fold under cursorzCClose all folds under cursorzaToggle foldzAToggle all folds under cursorzvOpen folds to show cursor linezMClose all foldszROpen all foldszmFold more (increase foldlevel)zrFold less (decrease foldlevel)zf{motion}Create foldzf'aFold to mark 'a':n,mfoldFold lines n to mzdDelete fold under cursorzDDelete all folds under cursorzEDelete all folds in filezjMove to next foldzkMove to previous fold[zMove to start of open fold]zMove to end of open fold: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 textCtrl+HDelete character before cursorCtrl+WDelete word before cursorCtrl+UDelete to start of lineCtrl+TIndent lineCtrl+DUnindent lineCtrl+JInsert newlineCtrl+MInsert newlineCtrl+R aInsert register 'a'Ctrl+R "Insert unnamed registerCtrl+R +Insert clipboardCtrl+R =Insert expression resultCtrl+R /Insert last searchCtrl+AInsert last inserted textCtrl+@Insert last inserted and exitCtrl+OExecute one normal commandCtrl+VInsert literal characterCtrl+V u1234Insert unicode characterCtrl+NNext completionCtrl+PPrevious completionCtrl+X Ctrl+FFilename completionCtrl+X Ctrl+LLine completionCtrl+X Ctrl+OOmni completionCtrl+X Ctrl+KDictionary completionCtrl+X Ctrl+]Tag completion:Enter command mode:!Execute shell command:!!Repeat last shell command:r !cmdInsert command output:w !cmdSend buffer to command:%!cmdFilter buffer through command:shOpen shellCtrl+ZSuspend Vimq:Open command history windowq/Open search history windowCtrl+FEdit command in window↑ / ↓Navigate command history:historyShow command history.Current line$Last line%All lines (same as 1,$)nLine number nn,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: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: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: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: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:set option!Toggle boolean option:set option?Show option value:set option&Reset to default:setlocal optionSet for current buffer:set spellEnable spell check:set spelllang=enSet spell language]sNext misspelled word[sPrevious misspelled wordz=Suggest correctionszgAdd word to dictionaryzwMark word as wrongzugUndo add to dictionary:diffsplit fileDiff with file:diffthisMake current window diff:diffoffTurn off diff mode:diffupdateUpdate diffdoObtain diff from otherdpPut diff to other]cNext difference[cPrevious difference:mksession file.vimSave session:source file.vimLoad sessionvim -S file.vimStart with session: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 itemCtrl+]Jump to tag definitionCtrl+TJump back from tag:tag nameJump to tag:tagsShow tag stack:tselectSelect from multiple tagsg]List matching tagsg Ctrl+]Jump or list tagsgaShow ASCII value of charg8Show UTF-8 bytes of chargfGo to file under cursorgxOpen URL under cursorCtrl+AIncrement numberCtrl+XDecrement numberg Ctrl+AIncrement sequence (visual):!sortSort selected lines:sortSort lines:sort!Sort reverse:sort uSort uniqueVim Modes Quick Reference
Default mode for navigation and commands
Esc
For typing and editing text
i, a, o, I, A, O
For selecting text
v, V, Ctrl+V
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