Vim Cheat Sheet
Essential Vim commands and shortcuts. Modes, navigation, editing, search/replace, visual mode, buffers, tabs, and macros.
Modes
| Key | Mode | Description |
|---|---|---|
Esc | Normal | Default mode for navigation and commands |
i | Insert | Insert text before cursor |
I | Insert | Insert at beginning of line |
a | Insert | Insert (append) after cursor |
A | Insert | Insert at end of line |
o | Insert | Open new line below and insert |
O | Insert | Open new line above and insert |
v | Visual | Character-wise visual selection |
V | Visual Line | Line-wise visual selection |
Ctrl+v | Visual Block | Block (column) visual selection |
: | Command | Enter command-line mode |
R | Replace | Replace characters as you type |
Editing
| Key | Description |
|---|---|
r{char} | Replace single character |
s | Delete character and enter insert mode |
S or cc | Delete line contents and enter insert mode |
c{motion} | Change (delete + insert). e.g., cw = change word |
C | Change from cursor to end of line |
ciw | Change inner word (delete word, enter insert) |
ci" | Change inside quotes |
ci( | Change inside parentheses |
ca{ | Change around braces (including braces) |
J | Join current line with next |
u | Undo |
Ctrl+r | Redo |
. | 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
| Key | Description |
|---|---|
x | Delete character under cursor |
X | Delete character before cursor |
dd | Delete (cut) current line |
d{motion} | Delete by motion (e.g., dw, d$, dG) |
D | Delete from cursor to end of line |
diw | Delete inner word |
di" | Delete inside quotes |
{n}dd | Delete n lines |
yy | Yank (copy) current line |
y{motion} | Yank by motion (e.g., yw, y$) |
{n}yy | Yank n lines |
p | Paste after cursor / below current line |
P | Paste before cursor / above current line |
"+y | Yank to system clipboard |
"+p | Paste from system clipboard |
Search & Replace
| Key / Command | Description |
|---|---|
/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 highlighting |
:%s/old/new/g | Replace all in file |
:%s/old/new/gc | Replace all with confirmation |
:s/old/new/g | Replace all in current line |
:5,10s/old/new/g | Replace in lines 5-10 |
:'<,'>s/old/new/g | Replace in visual selection |
Visual Mode
| Key | Description |
|---|---|
v | Start character visual mode |
V | Start line visual mode |
Ctrl+v | Start block visual mode |
o | Move to other end of selection |
d | Delete selection |
y | Yank selection |
c | Change selection |
> / < | Indent / unindent selection |
U / u | Uppercase / lowercase selection |
gv | Reselect 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
| Command | Description |
|---|---|
:w | Save file |
:w filename | Save as |
:q | Quit (fails if unsaved changes) |
:q! | Quit without saving |
:wq or :x or ZZ | Save and quit |
:e filename | Open file |
:e! | Reload file (discard changes) |
:r filename | Insert file contents below cursor |
:r !command | Insert command output |
:saveas filename | Save as and switch to new file |
Windows & Tabs
| Key / Command | Description |
|---|---|
:sp file | Horizontal split |
:vsp file | Vertical split |
Ctrl+w w | Cycle between windows |
Ctrl+w h/j/k/l | Move 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 |
:close | Close current window |
:only | Close all other windows |
:tabnew file | Open file in new tab |
gt / gT | Next / previous tab |
:tabclose | Close current tab |
:ls | List buffers |
:bn / :bp | Next / previous buffer |
:bd | Close buffer |
Macros & Registers
| Key | Description |
|---|---|
qa | Start recording macro into register 'a' |
q | Stop recording |
@a | Play macro 'a' |
@@ | Replay last macro |
10@a | Play macro 'a' 10 times |
"ay | Yank into register 'a' |
"ap | Paste from register 'a' |
:reg | Show all registers |
ma | Set mark 'a' at current position |
'a | Jump to mark 'a' |
:marks | Show 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