← Home

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 mode
iEnter Insert mode — type text before the cursor
aEnter Insert mode — type text after the cursor
IEnter Insert mode at the beginning of the line
AEnter Insert mode at the end of the line
oOpen a new line below and enter Insert mode
OOpen a new line above and enter Insert mode
vEnter 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 type
gvRe-select the previous visual selection

Navigation

h / j / k / lMove left / down / up / right (one character or line)
wJump forward to the start of the next word
WJump forward to the start of the next WORD (space-delimited)
bJump backward to the start of the previous word
BJump backward to the start of the previous WORD
eJump forward to the end of the current/next word
EJump forward to the end of the current/next WORD
0Jump to the first column of the line
^Jump to the first non-blank character of the line
$Jump to the end of the line
ggJump to the first line of the file
GJump to the last line of the file
:<number>Jump to a specific line number (e.g. :42)
Ctrl-dScroll down half a page
Ctrl-uScroll up half a page
Ctrl-fScroll forward one full page
Ctrl-bScroll backward one full page
f<char>Jump forward to the next occurrence of <char> on the line
F<char>Jump backward to the previous occurrence of <char>
t<char>Jump forward to just before <char> on the line
T<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 screen
zzCenter the current line in the viewport
zt / zbScroll current line to the top / bottom of the viewport

Editing

i / aInsert before / after the cursor
I / AInsert at beginning / end of line
o / OOpen new line below / above and enter Insert mode
xDelete the character under the cursor
XDelete the character before the cursor (backspace)
ddDelete (cut) the entire current line
DDelete from cursor to end of line
d<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 Insert
CChange from cursor to end of line
c<motion>Change text covered by a motion (cw, c$, ciw, etc.)
ci" / ci( / ci{Change inside quotes, parentheses, or braces
r<char>Replace the single character under the cursor
REnter Replace mode — overwrite characters continuously
sDelete character under cursor and enter Insert mode
SDelete entire line and enter Insert mode (same as cc)
JJoin the current line with the next line
gJJoin lines without adding a space
~Toggle case of the character under the cursor
gU<motion>Uppercase text covered by motion (gUiw, gUU)
gu<motion>Lowercase text covered by motion (guiw, guu)
uUndo the last change
Ctrl-rRedo the last undone change
.Repeat the last editing command
>>Indent the current line
<<Unindent the current line
==Auto-indent the current line

Copy & Paste

yyYank (copy) the entire current line
YYank the entire current line (same as yy)
ywYank from cursor to start of next word
y$Yank from cursor to end of line
y0Yank from cursor to beginning of line
yiwYank the current word (inner word)
yi" / yi( / yi{Yank inside quotes, parentheses, or braces
y<motion>Yank text covered by any motion
pPaste 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 text
dd 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 mode

Search & Replace

/<pattern>Search forward for a pattern
?<pattern>Search backward for a pattern
nJump to the next search match
NJump to the previous search match
*Search forward for the word under the cursor
#Search backward for the word under the cursor
g* / 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 selection
VStart line-wise visual selection
Ctrl-vStart block-wise (column) visual selection
oMove cursor to the other end of the selection
OMove cursor to the other corner (in block mode)
dDelete the selected text
yYank (copy) the selected text
cChange (delete and enter Insert mode) selected text
~Toggle case of selected text
U / uUppercase / lowercase the selected text
> / <Indent / unindent the selected lines
=Auto-indent the selected lines
:Enter command-line mode with range set to selection
gvRe-select the previous visual selection
I (block)Insert text at start of each line in block selection
A (block)Append text at end of each line in block selection
r<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 command

Buffers & 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 changes
ZQQuit 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 split
Ctrl-w sSplit current window horizontally
Ctrl-w vSplit current window vertically
Ctrl-w h / j / k / lMove focus to the left / down / up / right window
Ctrl-w H / J / K / LMove the current window to the far left / bottom / top / right
Ctrl-w =Make all windows equal size
Ctrl-w _Maximize current window height
Ctrl-w |Maximize current window width
Ctrl-w qClose the current window
Ctrl-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 tab
gt / gTGo to the next / previous tab
:tabcloseClose the current tab

Advanced

qaStart recording a macro into register a
qStop recording the current macro
@aPlay back the macro stored in register a
@@Repeat the last played macro
10@aPlay macro a ten times
maSet 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 position
zf<motion>Create a fold over the motion (zf3j folds 4 lines)
zoOpen a fold at the cursor
zcClose a fold at the cursor
zaToggle a fold open/closed
zROpen all folds in the file
zMClose 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 numerically
Ctrl-a / Ctrl-xIncrement / decrement the number under the cursor
g 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 topic

FAQ

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.

Related Resources