Vim Keyboard Shortcuts Cheat Sheet

Essential Vim keyboard shortcuts and commands. Navigate, edit, search, and manage files in Vim. Complete reference for beginners and pros.

Navigation — Basic Movement

ShortcutDescription
hMove cursor left one character
jMove cursor down one line
kMove cursor up one line
lMove cursor right one character
wJump forward to start of next word
WJump forward to start of next WORD (space-delimited)
bJump backward to start of previous word
BJump backward to start of previous WORD (space-delimited)
eJump forward to end of current word
EJump forward to end of current WORD (space-delimited)
0Move to the beginning of the line
^Move to the first non-blank character of the line
$Move to the end of the line
ggGo to the first line of the file
GGo to the last line of the file
5G or :5Go to line 5 (replace 5 with any line number)
HMove cursor to top of screen (High)
MMove cursor to middle of screen (Middle)
LMove cursor to bottom of screen (Low)
Ctrl + fScroll forward one full screen (page down)
Ctrl + bScroll backward one full screen (page up)
Ctrl + dScroll down half a screen
Ctrl + uScroll up half a screen
%Jump to matching bracket ( ), [ ], or { }
f{char}Move forward to next occurrence of {char} on current line
F{char}Move backward to previous occurrence of {char} on current line
t{char}Move forward to just before {char} on current line
;Repeat last f, F, t, or T motion forward
,Repeat last f, F, t, or T motion backward
}Jump to next paragraph (blank line)
{Jump to previous paragraph (blank line)

Editing — Insert Mode

ShortcutDescription
iInsert before cursor
IInsert at the beginning of the line
aAppend after cursor
AAppend at the end of the line
oOpen a new line below and enter insert mode
OOpen a new line above and enter insert mode
EscExit insert mode and return to normal mode

Editing — Delete, Change, Copy, Paste

ShortcutDescription
xDelete the character under the cursor
XDelete the character before the cursor
ddDelete (cut) the entire current line
dwDelete from cursor to start of next word
d$ or DDelete from cursor to the end of the line
d0Delete from cursor to the beginning of the line
dggDelete from current line to the beginning of the file
dGDelete from current line to the end of the file
d%Delete to matching bracket
ccChange (replace) the entire current line
cwChange from cursor to start of next word
c$ or CChange from cursor to the end of the line
sDelete character under cursor and enter insert mode
SDelete entire line and enter insert mode (same as cc)
r{char}Replace the character under cursor with {char}
REnter replace mode (overwrite characters as you type)
yyYank (copy) the entire current line
ywYank from cursor to start of next word
y$Yank from cursor to the end of the line
pPaste after cursor (or below current line for full lines)
PPaste before cursor (or above current line for full lines)
uUndo the last change
Ctrl + rRedo the last undone change
.Repeat the last editing command
JJoin the current line with the next line
~Toggle case of the character under cursor
>>Indent the current line
<<Un-indent the current line

Search & Replace

CommandDescription
/patternSearch forward for pattern
?patternSearch backward for pattern
nRepeat search in the same direction
NRepeat search in the opposite direction
*Search forward for the word under the cursor
#Search backward for the word under the cursor
:s/old/new/Replace first occurrence of old with new on the current line
:s/old/new/gReplace all occurrences of old with new on the current line
:%s/old/new/gReplace all occurrences of old with new in the entire file
:%s/old/new/gcReplace all occurrences with confirmation for each match
:nohClear search highlighting

Visual Mode

ShortcutDescription
vEnter visual (character) mode — select text character by character
VEnter visual line mode — select entire lines
Ctrl + vEnter visual block mode — select a rectangular block
gvReselect the last visual selection
oMove to the other end of the selection (in visual mode)
dDelete the selected text (in visual mode)
yYank (copy) the selected text (in visual mode)
cChange the selected text (in visual mode)
>Indent the selected text (in visual mode)
<Un-indent the selected text (in visual mode)
~Toggle case of selected text (in visual mode)
UUppercase selected text (in visual mode)
uLowercase selected text (in visual mode)

File Operations

CommandDescription
:wSave (write) the current file
:w filenameSave as a new file with the given name
:qQuit Vim (fails if there are unsaved changes)
:q!Quit without saving (force quit)
:wq or :xSave and quit
ZZSave and quit (shortcut, no colon needed)
ZQQuit without saving (shortcut, no colon needed)
:e filenameOpen a file for editing
:e!Reload the current file, discarding changes
:sp filenameOpen a file in a horizontal split
:vsp filenameOpen a file in a vertical split
:r filenameRead and insert a file below the cursor
:r !commandInsert the output of a shell command below the cursor

Buffers & Windows

CommandDescription
:ls or :buffersList all open buffers
:bnSwitch to the next buffer
:bpSwitch to the previous buffer
:bdClose (delete) the current buffer
:b2Switch to buffer number 2
Ctrl + w sSplit the window horizontally
Ctrl + w vSplit the window vertically
Ctrl + w wCycle through open windows
Ctrl + w hMove to the window on the left
Ctrl + w jMove to the window below
Ctrl + w kMove to the window above
Ctrl + w lMove to the window on the right
Ctrl + w qClose the current window
Ctrl + w oClose all windows except the current one
Ctrl + w =Make all windows equal size
Ctrl + w +Increase current window height
Ctrl + w -Decrease current window height
:tabnewOpen a new tab
:tabn or gtGo to the next tab
:tabp or gTGo to the previous tab
:tabcloseClose the current tab

Macros

CommandDescription
q{register}Start recording a macro into register (e.g., qa records into register a)
qStop recording the macro
@{register}Play back the macro from register (e.g., @a)
@@Replay the last played macro
5@aPlay macro in register a five times
:regView the contents of all registers (including macros)

Marks

CommandDescription
m{a-z}Set a local mark (e.g., ma sets mark a in current buffer)
m{A-Z}Set a global mark (works across files)
'{mark}Jump to the line of the mark (e.g., 'a)
`{mark}Jump to the exact position of the mark (e.g., `a)
''Jump back to the line before the last jump
``Jump back to the exact position before the last jump
:marksList all current marks
:delmarks aDelete mark a
:delmarks!Delete all lowercase marks