Appearance
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 cursorModes
| Mode | How to enter | What it does |
|---|---|---|
| Normal | Esc | Navigate and run commands — this is home |
| Insert | i, a, o, I, A, O | Type text |
| Visual | v, V, Ctrl+v | Select text |
| Command | : | Run Ex commands (save, quit, substitute…) |
| Replace | R | Overwrite characters as you type |
Start and end every editing session in Normal mode. If something feels broken, hit
Esca couple of times.
Navigation
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 42Word
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 bottomFile
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 lastEditing
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 aboveDelete
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 bottomChange (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 quotesYank (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 lineUndo & 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 historyIndent
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 fileRepeat
vim
. Repeat last change
; Repeat last f/t search
, Repeat last f/t search (backwards)
@: Repeat last command-line commandSearch & Replace
Search
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 highlightSubstitute
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 selectionUseful Substitute Flags
| Flag | Meaning |
|---|---|
g | All matches on each line |
c | Confirm each replacement |
i | Case-insensitive |
I | Case-sensitive (override ignorecase) |
Visual Mode
vim
v Character selection
V Line selection
Ctrl+v Block (column) selection
o Move to other end of selectionActions 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 linesBuffers, 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 bufferSplits
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 windowsTabs
vim
:tabnew file Open file in new tab
gt Next tab
gT Previous tab
:tabclose Close current tabFile & 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 sessionMarks & 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 marksMacros
vim
qa Start recording macro into register 'a'
q Stop recording
@a Play macro 'a'
@@ Repeat last macro
10@a Play macro 'a' 10 timesCommon Patterns
Rename a word throughout a file
vim
:%s/\bOldName\b/NewName/gcDelete all blank lines
vim
:g/^$/dSort selected lines
vim
:'<,'>sortAlign columns (requires column)
vim
:'<,'>!column -tOpen a terminal
vim
:terminal " Vim 8+ onlyRun a shell command and insert output
vim
:r !dateQuick Reference
| Task | Command |
|---|---|
| Save | :w |
| Quit | :q / :q! |
| Save and quit | :wq / ZZ |
| Undo | u |
| Redo | Ctrl+r |
| Copy line | yy |
| Cut line | dd |
| Paste | p |
| Search | /pattern |
| Next search match | n |
| Replace all in file | :%s/old/new/g |
| Start of file | gg |
| End of file | G |
| Go to line | :42 |
| Open file | :e file |
| Split vertical | Ctrl+w v |
| Split horizontal | Ctrl+w s |
| Move between splits | Ctrl+w hjkl |
| List buffers | :ls |
| Next buffer | :bn |
| Indent line | >> |
| Auto-indent file | gg=G |
| Toggle comment (vim-commentary) | gcc |
| Record macro | qa … q |
| Play macro | @a |
Related
- Vim Setup — Full Vim configuration guide with plugins and customization