Vim / Neovim Cheatsheet
Every essential Vim command: modes, motions, editing, registers, search, buffers, windows, and visual mode, with keys and real use cases.117 commands · 7 sections
Vim is a modal editor: the same keys do different things depending on the mode. This cheatsheet covers the commands you use daily: normal-mode motions and editing, insert mode, visual selection, search and replace, registers, buffers, windows, tabs, and macros.
Keys are shown in Vim notation: w moves word-by-word, dd deletes a line, and so on. Master these and you never touch the mouse again.
Modes & Basics17
iaoOEsc:w:q:wq:q!:e <file>:e!:set number:set relativenumber:nohuCtrl-r:help <topic>Navigation22
h j k lw / be / ge0$^ggG<n>GCtrl-d / Ctrl-uCtrl-f / Ctrl-bH / M / L{ / }( / )f<char> / F<char>t<char> / T<char>; / ,%gdgi``Ctrl-o / Ctrl-iEditing & Clipboard28
xXdddwd$d0Dciwci"ci(ci{ct<char>ccr<char>Ryyywy$pP"*yy"*pggdGdG.>> / <<=GJSearch & Replace13
/pattern?patternn / N*:s/old/new/:s/old/new/g:%s/old/new/g:%s/old/new/gc:s/old/new/gI:%s/\<word\>/new/g:g/pattern/d:v/pattern/d:%s/\d\+/NUM/gBuffers, Windows & Tabs14
:ls:bn / :bp:b <name>:bd:split:vsplitCtrl-w wCtrl-w h/j/k/lCtrl-w _Ctrl-w =Ctrl-w o:tabnew <file>gt / gT:tabsVisual Mode12
vVCtrl-vviwvipvi" / vi( / vi{y (in visual)d (in visual)c (in visual)> (in visual)u / U (in visual)gvMacros, Marks & Folds11
qa ... q@a10@ama`a:markszfzo / zczR / zM:sort:g/^/m0Vim / Neovim Cheatsheet
Every essential Vim command: modes, motions, editing, registers, search, buffers, windows, and visual mode, with keys and real use cases.
Vim is a modal editor: the same keys do different things depending on the mode. This cheatsheet covers the commands you use daily: normal-mode motions and editing, insert mode, visual selection, search and replace, registers, buffers, windows, tabs, and macros.
Keys are shown in Vim notation: w moves word-by-word, dd deletes a line, and so on. Master these and you never touch the mouse again.
Modes & Basics
i: Enter insert mode before the cursor: start typing.a: Enter insert mode AFTER the cursor.o: Open a new line below and enter insert mode.O: Open a new line ABOVE and enter insert mode.Esc: Return to normal mode: the mode where keys navigate and edit.:w: Save the file.:q: Quit.:wq: Save and quit.:q!: Quit WITHOUT saving: abandon changes.:e <file>: Open another file in the current buffer.:e!: Reload the file from disk, discarding changes.:set number: Show line numbers.:set relativenumber: Relative line numbers: jump distances are visible.:noh: Clear search highlighting.u: Undo.Ctrl-r: Redo.:help <topic>: Open built-in help: the best Vim documentation.Navigation
h j k l: Move left, down, up, right: the home-row motion keys.w / b: Next / previous word start.e / ge: Next / previous word END.0: Jump to the start of the line (column 0).$: Jump to the end of the line.^: Jump to the first non-whitespace character.gg: Jump to the first line of the file.G: Jump to the last line.<n>G: Jump to line n.Ctrl-d / Ctrl-u: Scroll down / up half a screen: page without losing context.Ctrl-f / Ctrl-b: Page forward / backward a full screen.H / M / L: Jump to the top / middle / bottom of the screen.{ / }: Jump to the previous / next paragraph: code blocks.( / ): Jump to the previous / next sentence.f<char> / F<char>: Jump to the next / previous occurrence of a character on the line.t<char> / T<char>: Jump to just BEFORE the character: f then change position.; / ,: Repeat / reverse the last f/t motion.%: Jump to the matching bracket: paren, brace, bracket.gd: Go to the definition of the identifier under the cursor.gi: Return to the last insert position: resume typing where you left off.``: Jump back to the previous position: the goto-return.Ctrl-o / Ctrl-i: Jump back / forward through the jump list: navigation history.Editing & Clipboard
x: Delete the character under the cursor.X: Delete the character BEFORE the cursor.dd: Delete the whole line.dw: Delete from the cursor to the end of the word.d$: Delete to the end of the line.d0: Delete to the start of the line.D: Delete to end of line: shorthand for d$.ciw: Change the whole word under the cursor: the most-used command.ci": Change everything inside quotes.ci(: Change everything inside parentheses.ci{: Change everything inside braces.ct<char>: Change up to (not including) a character.cc: Replace the whole line: delete and enter insert mode.r<char>: Replace the single character under the cursor.R: Enter replace mode: overwrite as you type.yy: Yank (copy) the whole line.yw: Yank the word.y$: Yank to the end of the line.p: Paste AFTER the cursor (or below the line).P: Paste BEFORE the cursor (or above the line)."*yy: Yank into the system clipboard: share with other apps."*p: Paste FROM the system clipboard.ggdG: Delete the ENTIRE file content: gg then dG.dG: Delete from the cursor to the end of the file..: Repeat the last change: the macro for one action.>> / <<: Indent / unindent the current line.=G: Auto-format (indent) to the end of the file.J: Join the next line onto the current one.Search & Replace
/pattern: Search forward: the command line shows your pattern.?pattern: Search backward.n / N: Next / previous search match.*: Search for the exact word under the cursor: the fastest search.:s/old/new/: Replace first occurrence on the current line.:s/old/new/g: Replace ALL occurrences on the current line.:%s/old/new/g: Replace ALL occurrences in the whole file.:%s/old/new/gc: Replace globally with confirmation: review each change.:s/old/new/gI: Case-insensitive replace.:%s/\<word\>/new/g: Whole-word replace: no partial matches.:g/pattern/d: Delete every line matching a pattern.:v/pattern/d: Delete every line NOT matching: keep only matches.:%s/\d\+/NUM/g: Replace with regex: search patterns are regex.Buffers, Windows & Tabs
:ls: List all open buffers.:bn / :bp: Go to the next / previous buffer.:b <name>: Jump to a buffer by name or number.:bd: Close the current buffer (file tab).:split: Split horizontally: two files stacked.:vsplit: Split vertically: side-by-side diff view.Ctrl-w w: Cycle focus between split windows.Ctrl-w h/j/k/l: Move focus to the window in that direction.Ctrl-w _: Maximize the current window vertically.Ctrl-w =: Equalize all window sizes.Ctrl-w o: Close all other windows: focus only the current one.:tabnew <file>: Open a file in a new tab.gt / gT: Next / previous tab.:tabs: List all tabs.Visual Mode
v: Character-wise visual mode: select exact characters.V: Line-wise visual mode: select whole lines.Ctrl-v: Block visual mode: select a rectangle. Multi-line column edits.viw: Select the word under the cursor.vip: Select the whole paragraph.vi" / vi( / vi{: Select inside quotes / parens / braces.y (in visual): Yank the selection.d (in visual): Delete the selection.c (in visual): Change the selection: delete and enter insert mode.> (in visual): Indent the selection.u / U (in visual): Lowercase / uppercase the selection.gv: Re-select the last visual selection.Macros, Marks & Folds
qa ... q: Record a macro into register a: press qa, do the actions, press q.@a: Play back macro a.10@a: Play macro a 10 times: repeat a transformation across lines.ma: Set mark a at the cursor position.`a: Jump to mark a.:marks: List all marks.zf: Create a fold over the current motion (e.g. zfap for paragraph).zo / zc: Open / close a fold.zR / zM: Open ALL / close ALL folds.:sort: Sort the current selection or file lines.:g/^/m0: Reverse the file: every line moved to the top in order.Frequently asked questions
How do I exit Vim?
Type :q to quit, :wq or ZZ to save and quit, :q! to quit without saving. If you are stuck in insert mode press Esc first. Vim keys: Esc returns to Normal mode, then use the colon commands.
What are Vim modes?
Normal mode is the default for navigation and commands (hjkl to move). Insert mode (i) types text. Visual mode (v) selects text for operations. Command-line mode (:) runs ex commands like :w and :%s.
How do I search and replace?
Search forward with /pattern and backward with ?pattern. Replace globally with :%s/old/new/g: add c for confirmation, use c for case-insensitive, and for word boundaries.
How do I copy and paste?
In Normal mode, yy copies a line, yw copies a word, and p pastes after the cursor. To copy between Vim sessions use the system clipboard: "+y to copy and "+p to paste.