Vim Commands Cheat Sheet
06/06/2025
A comprehensive reference guide to essential Vim commands for efficient text editing
Note: Vim is a modal editor. Most commands work in normal mode (press Esc to ensure you're in normal mode). Press
i to enter insert mode for typing text.
Global Commands
Open help for keyword
:h[elp] keyword
Save file as
:sav[eas] file
Close current pane
:clo[se]
Open a terminal window
:ter[minal]
Open man page for word under cursor
K
Run Vim tutorial in terminal
vimtutor
Cursor Movement
Move cursor left/down/up/right
h / j / k / l
Move cursor down/up (multi-line text)
gj / gk
Move to top/middle/bottom of screen
H / M / L
Jump to start/end of word
w / e
Jump backwards to start/end of word
b / ge
Jump to start/end of line
0 / $
Jump to first non-blank character of line
^
Go to first/last line of document
gg / G
Go to line 5
5gg or 5G
Jump to matching bracket
%
Insert Mode
Insert before/at beginning of line
i / I
Append after cursor/at end of line
a / A
Open new line below/above
o / O
Insert at end of word
ea
Delete character/word before cursor
Ctrl+h / Ctrl+w
Indent/de-indent line
Ctrl+t / Ctrl+d
Auto-complete next/previous match
Ctrl+n / Ctrl+p
Exit insert mode
Esc or Ctrl+c
Editing
Replace single character
r
Replace multiple characters
R
Join line below with current line
J
Change case (lowercase/uppercase)
gu / gU
Change entire line
cc
Change to end of line
C
Change entire word
ciw
Undo/redo
u / Ctrl+r
Repeat last command
.
Visual Mode
Start visual mode (character-wise)
v
Start visual mode (line-wise)
V
Start visual block mode
Ctrl+v
Move to other end of marked area
o
Move to other corner of block
O
Mark a word/paragraph
aw / ap
Mark a block with ()/{}/<>
ab / aB / a>
Exit visual mode
Esc or Ctrl+c
Visual Commands
Shift text right/left
> / <
Yank (copy) marked text
y
Delete marked text
d
Switch case
~
Change marked text to lowercase
u
Change marked text to uppercase
U
Cut and Paste
Yank (copy) a line
yy
Yank 2 lines
2yy
Yank word under cursor
yiw
Yank to end of line
y$
Put (paste) after cursor
p
Put (paste) before cursor
P
Delete (cut) a line
dd
Delete (cut) 2 lines
2dd
Delete (cut) word under cursor
diw
Delete to end of line
D
Search and Replace
Search forward for pattern
/pattern
Search backward for pattern
?pattern
Repeat search forward/backward
n / N
Replace all in current line
:s/old/new/g
Replace all in file
:%s/old/new/g
Replace with confirmation
:%s/old/new/gc
Search for word under cursor
*
Search backward for word under cursor
#
Working with Multiple Files
Edit a file in new buffer
:e filename
Split window horizontally
:split filename
Split window vertically
:vsplit filename
Switch between windows
Ctrl+w arrows
Close current window
:q
Close all windows except current
:only
List all open buffers
:ls
Go to next/previous buffer
:bn / :bp
Tabs
Open file in new tab
:tabedit filename
Go to next/previous tab
gt / gT
Go to tab number #
#gt
Close current tab
:tabclose
Close all other tabs
:tabonly
Indentation
Indent line one shiftwidth
>>
De-indent line one shiftwidth
<<
Indent a block with () or {}
>% or >iB
Re-indent entire file
gg=G
Re-indent current line
==
Macros
Record macro a
qa
Stop recording macro
q
Run macro a
@a
Run macro a on lines 5-10
:5,10norm! @a
Rerun last run macro
@@
Exiting
Write (save) and quit
:wq or ZZ
Quit (fails if unsaved changes)
:q
Quit without saving (discard changes)
:q! or ZQ
Write (save) current file
:w
Write to specified file
:w filename
Write and quit all tabs
:wqa