Vim Cheat Sheet

Essential Vim commands and shortcuts. Modes, navigation, editing, search/replace, visual mode, buffers, tabs, and macros.

Modes

KeyModeDescription
EscNormalDefault mode for navigation and commands
iInsertInsert text before cursor
IInsertInsert at beginning of line
aInsertInsert (append) after cursor
AInsertInsert at end of line
oInsertOpen new line below and insert
OInsertOpen new line above and insert
vVisualCharacter-wise visual selection
VVisual LineLine-wise visual selection
Ctrl+vVisual BlockBlock (column) visual selection
:CommandEnter command-line mode
RReplaceReplace characters as you type

Editing

KeyDescription
r{char}Replace single character
sDelete character and enter insert mode
S or ccDelete line contents and enter insert mode
c{motion}Change (delete + insert). e.g., cw = change word
CChange from cursor to end of line
ciwChange inner word (delete word, enter insert)
ci"Change inside quotes
ci(Change inside parentheses
ca{Change around braces (including braces)
JJoin current line with next
uUndo
Ctrl+rRedo
.Repeat last change
~Toggle case of character
>>Indent line
<<Unindent line
=Auto-indent (e.g., gg=G to indent entire file)
Tip: The c, d, y commands follow the pattern: operator + motion. E.g., d3w = delete 3 words, y$ = yank to end of line, ci" = change inside quotes.

Copy, Paste & Delete

KeyDescription
xDelete character under cursor
XDelete character before cursor
ddDelete (cut) current line
d{motion}Delete by motion (e.g., dw, d$, dG)
DDelete from cursor to end of line
diwDelete inner word
di"Delete inside quotes
{n}ddDelete n lines
yyYank (copy) current line
y{motion}Yank by motion (e.g., yw, y$)
{n}yyYank n lines
pPaste after cursor / below current line
PPaste before cursor / above current line
"+yYank to system clipboard
"+pPaste from system clipboard

Visual Mode

KeyDescription
vStart character visual mode
VStart line visual mode
Ctrl+vStart block visual mode
oMove to other end of selection
dDelete selection
yYank selection
cChange selection
> / <Indent / unindent selection
U / uUppercase / lowercase selection
gvReselect last visual selection
# Block insert (add text to multiple lines)
Ctrl+v → select column → I → type text → Esc

# Block append
Ctrl+v → select column → A → type text → Esc

File Operations

CommandDescription
:wSave file
:w filenameSave as
:qQuit (fails if unsaved changes)
:q!Quit without saving
:wq or :x or ZZSave and quit
:e filenameOpen file
:e!Reload file (discard changes)
:r filenameInsert file contents below cursor
:r !commandInsert command output
:saveas filenameSave as and switch to new file

Windows & Tabs

Key / CommandDescription
:sp fileHorizontal split
:vsp fileVertical split
Ctrl+w wCycle between windows
Ctrl+w h/j/k/lMove to left/down/up/right window
Ctrl+w =Make all windows equal size
Ctrl+w _Maximize current window height
Ctrl+w |Maximize current window width
:closeClose current window
:onlyClose all other windows
:tabnew fileOpen file in new tab
gt / gTNext / previous tab
:tabcloseClose current tab
:lsList buffers
:bn / :bpNext / previous buffer
:bdClose buffer

Macros & Registers

KeyDescription
qaStart recording macro into register 'a'
qStop recording
@aPlay macro 'a'
@@Replay last macro
10@aPlay macro 'a' 10 times
"ayYank into register 'a'
"apPaste from register 'a'
:regShow all registers
maSet mark 'a' at current position
'aJump to mark 'a'
:marksShow all marks

Configuration

" Essential .vimrc settings
set number            " show line numbers
set relativenumber    " relative line numbers
set tabstop=4          " tab = 4 spaces
set shiftwidth=4       " indent = 4 spaces
set expandtab          " use spaces instead of tabs
set autoindent         " auto indent new lines
set smartindent        " smart auto indent
set ignorecase         " case insensitive search
set smartcase          " case sensitive if uppercase used
set hlsearch           " highlight search results
set incsearch          " incremental search
set wrap               " wrap long lines
set mouse=a            " enable mouse
set clipboard=unnamedplus  " use system clipboard
syntax on              " syntax highlighting
set cursorline         " highlight current line