Vim Commands Cheatsheet
Complete Vim and Neovim reference — modes, navigation, editing, registers, search & replace, visual mode, window management, and advanced features. Bookmark this and master Vim one command at a time.
Modes
EscReturn to Normal mode from any other modeiEnter Insert mode — type text before the cursoraEnter Insert mode — type text after the cursorIEnter Insert mode at the beginning of the lineAEnter Insert mode at the end of the lineoOpen a new line below and enter Insert modeOOpen a new line above and enter Insert modevEnter Visual mode (character-wise selection)VEnter Visual Line mode (select entire lines)Ctrl-vEnter Visual Block mode (rectangular column selection):Enter Command-line mode (execute Ex commands)REnter Replace mode — overwrite characters as you typegvRe-select the previous visual selectionNavigation
h / j / k / lMove left / down / up / right (one character or line)wJump forward to the start of the next wordWJump forward to the start of the next WORD (space-delimited)bJump backward to the start of the previous wordBJump backward to the start of the previous WORDeJump forward to the end of the current/next wordEJump forward to the end of the current/next WORD0Jump to the first column of the line^Jump to the first non-blank character of the line$Jump to the end of the lineggJump to the first line of the fileGJump to the last line of the file:<number>Jump to a specific line number (e.g. :42)Ctrl-dScroll down half a pageCtrl-uScroll up half a pageCtrl-fScroll forward one full pageCtrl-bScroll backward one full pagef<char>Jump forward to the next occurrence of <char> on the lineF<char>Jump backward to the previous occurrence of <char>t<char>Jump forward to just before <char> on the lineT<char>Jump backward to just after <char> on the line;Repeat the last f/F/t/T motion forward,Repeat the last f/F/t/T motion backward%Jump to matching bracket — (), {}, []{Jump to the previous blank line (paragraph up)}Jump to the next blank line (paragraph down)H / M / LMove cursor to top / middle / bottom of the screenzzCenter the current line in the viewportzt / zbScroll current line to the top / bottom of the viewportEditing
i / aInsert before / after the cursorI / AInsert at beginning / end of lineo / OOpen new line below / above and enter Insert modexDelete the character under the cursorXDelete the character before the cursor (backspace)ddDelete (cut) the entire current lineDDelete from cursor to end of lined<motion>Delete text covered by a motion (dw, d$, d2j, etc.)diw / dawDelete inner word / a word (including surrounding space)di" / da"Delete inside quotes / around quotes (also works with ', (, {, [)ccChange (replace) entire line — deletes line and enters InsertCChange from cursor to end of linec<motion>Change text covered by a motion (cw, c$, ciw, etc.)ci" / ci( / ci{Change inside quotes, parentheses, or bracesr<char>Replace the single character under the cursorREnter Replace mode — overwrite characters continuouslysDelete character under cursor and enter Insert modeSDelete entire line and enter Insert mode (same as cc)JJoin the current line with the next linegJJoin lines without adding a space~Toggle case of the character under the cursorgU<motion>Uppercase text covered by motion (gUiw, gUU)gu<motion>Lowercase text covered by motion (guiw, guu)uUndo the last changeCtrl-rRedo the last undone change.Repeat the last editing command>>Indent the current line<<Unindent the current line==Auto-indent the current lineCopy & Paste
yyYank (copy) the entire current lineYYank the entire current line (same as yy)ywYank from cursor to start of next wordy$Yank from cursor to end of liney0Yank from cursor to beginning of lineyiwYank the current word (inner word)yi" / yi( / yi{Yank inside quotes, parentheses, or bracesy<motion>Yank text covered by any motionpPaste after the cursor (or below current line for line-wise)PPaste before the cursor (or above current line)gp / gPPaste and move cursor to end of pasted textdd then pCut a line (dd) and paste it elsewhere (p)"ayYank into register a (registers a-z available)"apPaste from register a"AyAppend to register a (uppercase appends)"+yYank to the system clipboard register"+pPaste from the system clipboard register:regShow contents of all registers"0pPaste from the yank register (last yank, not delete)"_dDelete without saving to any register (black hole)Ctrl-r <reg>Paste register contents in Insert/Command-line modeSearch & Replace
/<pattern>Search forward for a pattern?<pattern>Search backward for a patternnJump to the next search matchNJump to the previous search match*Search forward for the word under the cursor#Search backward for the word under the cursorg* / g#Like * / # but allow partial word matches:s/old/new/Replace first occurrence of old with new on current line:s/old/new/gReplace all occurrences on the current line:%s/old/new/gReplace all occurrences in the entire file:%s/old/new/gcReplace all with confirmation prompt for each match:%s/old/new/giReplace all, case-insensitive:'<,'>s/old/new/gReplace within the current visual selection:10,20s/old/new/gReplace within lines 10-20:nohClear search highlighting:set hlsearchEnable persistent search highlighting:set incsearchEnable incremental search (highlight as you type):set ignorecaseMake searches case-insensitive by default:set smartcaseCase-sensitive only when pattern has uppercase/\v<pattern>Use very-magic mode (less escaping needed for regex)Visual Mode
vStart character-wise visual selectionVStart line-wise visual selectionCtrl-vStart block-wise (column) visual selectionoMove cursor to the other end of the selectionOMove cursor to the other corner (in block mode)dDelete the selected textyYank (copy) the selected textcChange (delete and enter Insert mode) selected text~Toggle case of selected textU / uUppercase / lowercase the selected text> / <Indent / unindent the selected lines=Auto-indent the selected lines:Enter command-line mode with range set to selectiongvRe-select the previous visual selectionI (block)Insert text at start of each line in block selectionA (block)Append text at end of each line in block selectionr<char> (block)Replace every character in block with <char>JJoin all selected lines into one:sortSort the selected lines alphabetically:!<cmd>Filter selected text through an external commandBuffers & Windows
:e <file>Open a file in a new buffer:e!Reload the current file, discarding unsaved changes:wWrite (save) the current buffer:w <file>Save the current buffer to a new file (Save As):wqSave and quit:xSave and quit (only writes if changes exist)ZZSave and quit (Normal mode shortcut for :x):qQuit the current window (fails if unsaved changes):q!Quit without saving — discard all changesZQQuit without saving (Normal mode shortcut for :q!):qaQuit all windows:wqaSave all buffers and quit all windows:sp <file>Open file in a horizontal split:vsp <file>Open file in a vertical splitCtrl-w sSplit current window horizontallyCtrl-w vSplit current window verticallyCtrl-w h / j / k / lMove focus to the left / down / up / right windowCtrl-w H / J / K / LMove the current window to the far left / bottom / top / rightCtrl-w =Make all windows equal sizeCtrl-w _Maximize current window heightCtrl-w |Maximize current window widthCtrl-w qClose the current windowCtrl-w oClose all windows except the current one:bn / :bpGo to the next / previous buffer:bdClose (delete) the current buffer:lsList all open buffers:b <name>Switch to a buffer by partial filename match:tabnew <file>Open a file in a new tabgt / gTGo to the next / previous tab:tabcloseClose the current tabAdvanced
qaStart recording a macro into register aqStop recording the current macro@aPlay back the macro stored in register a@@Repeat the last played macro10@aPlay macro a ten timesmaSet mark a at the current cursor position'aJump to the line of mark a`aJump to the exact position of mark a:marksList all marks'. / `.Jump to the line / position of the last edit'' / ``Jump back to the previous positionzf<motion>Create a fold over the motion (zf3j folds 4 lines)zoOpen a fold at the cursorzcClose a fold at the cursorzaToggle a fold open/closedzROpen all folds in the filezMClose all folds in the file:!<cmd>Run an external shell command:r <file>Insert contents of a file below the cursor:r !<cmd>Insert output of a shell command below the cursor:sortSort all lines in the file (or visual selection):sort uSort and remove duplicate lines:sort nSort numericallyCtrl-a / Ctrl-xIncrement / decrement the number under the cursorg Ctrl-a (visual)Create incrementing sequence in visual block:set numberShow line numbers:set relativenumberShow relative line numbers:set pasteEnable paste mode (disables auto-indent for pasting):nmap / :imapShow or create key mappings for Normal / Insert mode:help <topic>Open Vim's built-in help for any command or topicFAQ
How do I exit Vim?
Press Esc to make sure you're in Normal mode, then type :q to quit (if no changes) or :wq to save and quit. If you want to discard changes, use :q!. The quickest shortcut is ZZ (save and quit) or ZQ (quit without saving) from Normal mode.
What is the difference between Vim and Neovim?
Neovim is a modern fork of Vim with a cleaner codebase, built-in LSP support, Lua scripting, async plugin architecture, and a built-in terminal emulator. Nearly all Vim commands work identically in Neovim. Neovim is backward-compatible and can use most Vim plugins, making it a drop-in upgrade for most users.
How do I enable syntax highlighting and line numbers?
In Vim, run :syntax on to enable syntax highlighting and :set number to show line numbers (:set relativenumber for relative). To make these persistent, add them to your ~/.vimrc file. In Neovim, add them to ~/.config/nvim/init.vim or init.lua.
How do macros work in Vim?
Press qa to start recording into register a (any letter works). Perform your editing commands, then press q to stop recording. Play it back with @a, and @@ to repeat. Use 10@a to run it 10 times. Macros are incredibly powerful for repetitive edits — record once, replay as many times as needed.