Vim Cheatsheet
A fast, practical reference. Commands are case-sensitive. <Leader> defaults to \ (or , if you set it so).
Start & Quit
vim file " open file
:n " go to line n
:w " write (save)
:w filename " save as
:q " quit
:q! " quit without saving
:wq / :x " write and quit
:wa " write all buffers
:qa " quit allModes & Inserts
i " insert before cursor
I " insert at line start
a " append after cursor
A " append at line end
o / O " open new line below/above
s / S " substitute char / whole line
cc / C " change line / to EOL
R " replace (overwrite) mode
Esc " back to Normal modeMovement (Normal Mode)
h j k l " left, down, up, right
w / b / e " next word / prev word / word end
W / B / E " WORD by spaces
0 / ^ / $ " start / first nonblank / end of line
gg / G " top / bottom of file
nG " go to line n
{ / } " previous / next blank-line block
( / ) " prev / next sentence
% " matching bracket/paren
H / M / L " top/middle/bottom of screen
zt / zz / zb " scroll line to top/center/bottom
Ctrl-u / d " half-page up/down
Ctrl-b / f " page up/downFind Characters (on line)
f{char} / F{char} " find next/prev char
t{char} / T{char} " till before/after char
; / , " repeat / reverse repeatSelect (Visual)
v " visual (chars)
V " visual line
Ctrl-v " visual block
o " swap anchor/cursor in visualEdit: Delete / Change / Yank (Copy) / Put (Paste)
d{motion} " delete
c{motion} " change (delete + insert)
y{motion} " yank (copy)
p / P " put after/before
x / X " delete char under/left
dd / cc / yy " operate on whole line
D / C / Y " to end of line (Y = yank line)
~ " toggle case (char or selection)
gu{motion} " make lowercase
gU{motion} " make uppercase
J / gJ " join with/without space
xp " swap two lettersCounts & Repeats
3w " move 3 words
5dd " delete 5 lines
. " repeat last change
u " undo
Ctrl-r " redoIndent & Format
>> / << " indent / outdent line
= " auto-indent selection/motion
=gq{motion} " reflow text (format)
:retab " fix tabs/spacesSearch & Replace
/word " forward search
?word " backward search
n / N " next / previous
* / # " search word under cursor (fwd/back)
:noh " remove highlight
:%s/old/new/g " replace in file
:%s/old/new/gc " confirm each
:.,$s/old/new/g " from here to end
:'<,'>s/old/new/g " in visual selection
\vpattern " very-magic (fewer escapes)Buffers, Tabs & Windows
" Buffers (open files in memory)
:ls " list buffers
:bn / :bp " next / previous buffer
:b # " alternate buffer
:bd " delete (close) buffer
" Tabs (tab pages)
:tabnew file " open in new tab
:tabn / :tabp " next / previous tab
:tabclose " close tab
:tabonly " close others
" Windows (splits)
:sp file " split horizontally
:vsp file " split vertically
Ctrl-w s / v " split current buffer
Ctrl-w h/j/k/l " move between windows
Ctrl-w = " equalize sizes
Ctrl-w _ | " max height / width
:q " closes current windowMarks & Jumps
m{a-z} " set mark (file-local)
'{a-z} " jump to line of mark
`{a-z} " jump to exact position
`` " jump back to previous position
'' " jump back to previous line
Ctrl-o / i " older / newer jumpsRegisters & System Clipboard
"" " unnamed register (default)
"0 " yanked text
"1..9 " delete history registers
"a..z " named registers
"+ / "* " system clipboard (GUI/with clipboard)
" Examples:
"+y " yank to system clipboard
"+p " paste from system clipboard
"ayy " yank current line to register a
"ap " paste from register aMacros
q{reg} " start recording into register
q " stop recording
@{reg} " play macro
@@ " repeat last macro
3@a " run macro a 3 timesFiles, Explore, and Info
:e file " open/reload file
:edit! " reload discarding changes
:Ex / :Sex " file explorer (netrw)
:pwd " print working dir
:echo expand('%:p') " full path of current fileFolding (built-in)
zf{motion} " create fold
za " toggle fold
zc / zo " close / open fold
zM / zR " close all / open all
set foldmethod=indent | marker | syntaxUseful Settings (put in vimrc)
set number " line numbers
set relativenumber " relative numbers
set ignorecase smartcase " smarter searching
set incsearch " live search
set hlsearch " highlight matches
set tabstop=4 shiftwidth=4 expandtab " spaces for tabs
set clipboard=unnamedplus " use system clipboard
set mouse=a " enable mouse (if desired)
syntax on
filetype plugin indent onCommand-Line Fu
:!cmd " run shell command (read-only)
:r !cmd " read command output into buffer
:r file " read file into current buffer below cursor
:w !sudo tee % " write current file with sudo
:help {topic} " open help (:h motion, :h visual, :h gq)Quick Reference Table
Task
Normal Mode Command
Save / Quit
:w / :q / :wq / :q!
Move by word
w / b / e
Line start / end
^ / $
Insert / Append
i / a
New line
o / O
Delete word / to EOL
dw / D
Yank line / Paste
yy / p
Undo / Redo
u / Ctrl-r
Search next
n
Visual modes
v / V / Ctrl-v
Split / Vsplit
:sp / :vsp
Next buffer / tab
:bn / :tabn
Tip: Nearly every action is operator + {motion}. Learn a few motions (w, $, fX, }) and operators (d, c, y, gU, gu) to compose powerful edits quickly.
Last updated
Was this helpful?