Skip to content

Vim Cheatsheet

Published: February 25, 2026 · Last edited: February 25, 2026

A practical reference for Vim commands you need mid-task — modes, navigation, editing, search, and splits.

The 30-Second Version

vim
i           Enter insert mode
Esc         Return to normal mode
:w          Save
:q          Quit
:wq         Save and quit
:q!         Quit without saving

/word       Search for word
n / N       Next / previous match

u           Undo
Ctrl+r      Redo

yy          Copy line
dd          Cut line
p           Paste after cursor

Modes

ModeHow to enterWhat it does
NormalEscNavigate and run commands — this is home
Inserti, a, o, I, A, OType text
Visualv, V, Ctrl+vSelect text
Command:Run Ex commands (save, quit, substitute…)
ReplaceROverwrite characters as you type

Start and end every editing session in Normal mode. If something feels broken, hit Esc a couple of times.


Character & Line

vim
h j k l     Left, down, up, right
0           Start of line
^           First non-blank character of line
$           End of line
gg          First line of file
G           Last line of file
:42         Jump to line 42

Word

vim
w           Next word start
b           Previous word start
e           Next word end
W B E       Same, but ignores punctuation (WORD)

Sentence & Paragraph

vim
(  )        Previous / next sentence
{  }        Previous / next paragraph (blank line)

Screen

vim
Ctrl+d      Half-page down (cursor moves)
Ctrl+u      Half-page up
Ctrl+f      Full page forward
Ctrl+b      Full page back
zz          Centre current line in window
zt          Current line to top
zb          Current line to bottom

File

vim
%           Jump to matching bracket/paren
gd          Go to definition (local)
gf          Open file under cursor
Ctrl+o      Jump back (previous location)
Ctrl+i      Jump forward
``          Jump to where you were last

Editing

Enter Insert Mode

vim
i           Before cursor
a           After cursor
I           Start of line
A           End of line
o           New line below
O           New line above

Delete

vim
x           Delete character under cursor
dd          Delete (cut) whole line
dw          Delete to next word
d$  (D)     Delete to end of line
dgg         Delete from here to top
dG          Delete from here to bottom

Change (Delete + Enter Insert)

vim
cw          Change word
cc  (S)     Change whole line
c$  (C)     Change to end of line
ci"         Change inside double quotes
ci(         Change inside parentheses
ci{         Change inside braces
ca"         Change around (including) double quotes

Yank (Copy) & Paste

vim
yy  (Y)     Copy whole line
yw          Copy word
y$          Copy to end of line
yi"         Copy inside quotes

p           Paste after cursor / below line
P           Paste before cursor / above line

Undo & Redo

vim
u           Undo
Ctrl+r      Redo
U           Undo all changes on current line
:earlier 5m Revert file to 5 minutes ago
:later 5m   Go 5 minutes forward in history

Indent

vim
>>          Indent line right
<<          Indent line left
>%          Indent to matching bracket
=G          Auto-indent from cursor to end of file
gg=G        Auto-indent entire file

Repeat

vim
.           Repeat last change
;           Repeat last f/t search
,           Repeat last f/t search (backwards)
@:          Repeat last command-line command

Search & Replace

vim
/pattern    Search forward
?pattern    Search backward
n           Next match
N           Previous match
*           Search for word under cursor (forward)
#           Search for word under cursor (backward)
:noh        Clear search highlight

Substitute

vim
:s/old/new          Replace first match on current line
:s/old/new/g        Replace all on current line
:%s/old/new/g       Replace all in file
:%s/old/new/gc      Replace all, confirm each
:'<,'>s/old/new/g   Replace in visual selection

Useful Substitute Flags

FlagMeaning
gAll matches on each line
cConfirm each replacement
iCase-insensitive
ICase-sensitive (override ignorecase)

Visual Mode

vim
v           Character selection
V           Line selection
Ctrl+v      Block (column) selection

o           Move to other end of selection

Actions on Selection

vim
d           Delete
y           Copy
c           Change (delete + insert)
>  <        Indent / dedent
~           Toggle case
:           Run command on selection (e.g., :sort, :!column -t)

Column Editing

vim
Ctrl+v      Enter block select
j j j       Expand selection down
I           Insert at start of each line
A           Append at end of each line
Esc Esc     Apply the edit to all selected lines

Buffers, Windows & Tabs

Buffers

vim
:e file     Open file in current buffer
:ls         List open buffers
:b2         Switch to buffer 2
:bn         Next buffer
:bp         Previous buffer
:bd         Close (delete) current buffer

Splits

vim
:sp file    Horizontal split
:vsp file   Vertical split
Ctrl+w s    Horizontal split (current file)
Ctrl+w v    Vertical split (current file)
Ctrl+w w    Cycle through windows
Ctrl+w hjkl Move to window left/down/up/right
Ctrl+w =    Equalise window sizes
Ctrl+w _    Maximise height
Ctrl+w |    Maximise width
:only       Close all other windows

Tabs

vim
:tabnew file    Open file in new tab
gt              Next tab
gT              Previous tab
:tabclose       Close current tab

File & Session

vim
:w              Save
:w filename     Save as
:wq  ZZ         Save and quit
:q!  ZQ         Quit without saving
:wa             Save all buffers
:qa             Quit all

:e!             Reload file from disk (discard changes)
:pwd            Show current directory
:cd path        Change directory

:mksession      Save session to Session.vim
vim -S          Restore a saved session

Marks & Jumps

vim
ma          Set mark 'a' at cursor
`a          Jump to mark 'a' (exact position)
'a          Jump to mark 'a' (start of line)
``          Jump to last position before jump
'.          Jump to last edit
Ctrl+o      Previous jump
Ctrl+i      Next jump
:marks      List all marks

Macros

vim
qa          Start recording macro into register 'a'
q           Stop recording
@a          Play macro 'a'
@@          Repeat last macro
10@a        Play macro 'a' 10 times

Common Patterns

Rename a word throughout a file

vim
:%s/\bOldName\b/NewName/gc

Delete all blank lines

vim
:g/^$/d

Sort selected lines

vim
:'<,'>sort

Align columns (requires column)

vim
:'<,'>!column -t

Open a terminal

vim
:terminal       " Vim 8+ only

Run a shell command and insert output

vim
:r !date

Quick Reference

TaskCommand
Save:w
Quit:q / :q!
Save and quit:wq / ZZ
Undou
RedoCtrl+r
Copy lineyy
Cut linedd
Pastep
Search/pattern
Next search matchn
Replace all in file:%s/old/new/g
Start of filegg
End of fileG
Go to line:42
Open file:e file
Split verticalCtrl+w v
Split horizontalCtrl+w s
Move between splitsCtrl+w hjkl
List buffers:ls
Next buffer:bn
Indent line>>
Auto-indent filegg=G
Toggle comment (vim-commentary)gcc
Record macroqaq
Play macro@a
  • Vim Setup — Full Vim configuration guide with plugins and customization