Editor
Vim Cheatsheet
Quick reference for Vim commands including modes, navigation, editing, search and replace, macros, registers, and window management.
Modes
| Key | Mode | Description |
|---|---|---|
Esc | Normal | Default mode for navigation and commands |
i | Insert | Insert before cursor |
a | Insert | Insert after cursor |
I | Insert | Insert at beginning of line |
A | Insert | Insert at end of line |
o | Insert | Open new line below |
O | Insert | Open new line above |
v | Visual | Character-wise selection |
V | Visual Line | Line-wise selection |
Ctrl+v | Visual Block | Block selection |
: | Command | Enter ex commands |
R | Replace | Replace characters as you type |
Navigation
Basic Movement
| Key | Description |
|---|---|
h j k l | Left, Down, Up, Right |
w | Next word start |
W | Next WORD start (whitespace-delimited) |
b | Previous word start |
B | Previous WORD start |
e | Next word end |
E | Next WORD end |
0 | Beginning of line |
^ | First non-blank character |
$ | End of line |
gg | First line of file |
G | Last line of file |
{n}G | Go to line n |
{ | Previous paragraph |
} | Next paragraph |
% | Matching bracket |
Ctrl+d | Half page down |
Ctrl+u | Half page up |
Ctrl+f | Full page down |
Ctrl+b | Full page up |
H | Top of screen |
M | Middle of screen |
L | Bottom of screen |
zz | Center current line on screen |
Editing
| Key | Description |
|---|---|
x | Delete character under cursor |
X | Delete character before cursor |
dd | Delete line |
D | Delete to end of line |
dw | Delete word |
d$ | Delete to end of line |
d0 | Delete to beginning of line |
cc | Change entire line |
C | Change to end of line |
cw | Change word |
ci" | Change inside quotes |
ca( | Change around parentheses |
yy | Yank (copy) line |
yw | Yank word |
y$ | Yank to end of line |
p | Paste after cursor |
P | Paste before cursor |
u | Undo |
Ctrl+r | Redo |
. | Repeat last command |
J | Join line below to current |
~ | Toggle case |
>> | Indent line |
<< | Unindent line |
== | Auto-indent line |
Text Objects
| Object | Description |
|---|---|
iw | Inner word |
aw | A word (including space) |
is | Inner sentence |
ip | Inner paragraph |
i" / i' / i` | Inside quotes |
a" / a' / a` | Around quotes |
i( / i) / ib | Inside parentheses |
i{ / i} / iB | Inside braces |
i[ / i] | Inside brackets |
it | Inside HTML/XML tag |
at | Around HTML/XML tag |
Search & Replace
| Command | Description |
|---|---|
/pattern | Search forward |
?pattern | Search backward |
n | Next match |
N | Previous match |
* | Search word under cursor (forward) |
# | Search word under cursor (backward) |
:s/old/new/ | Replace first 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 with confirmation |
:noh | Clear search highlighting |
Macros
| Command | Description |
|---|---|
qa | Start recording macro into register a |
q | Stop recording |
@a | Play macro from register a |
@@ | Replay last macro |
10@a | Play macro 10 times |
Registers
| Register | Description |
|---|---|
"a | Named register a-z |
"A | Append to register a |
"" | Default (unnamed) register |
"0 | Last yank |
"1-"9 | Last deletes |
"+ | System clipboard |
"* | Primary selection (X11) |
"/ | Last search pattern |
": | Last command |
". | Last inserted text |
"% | Current filename |
Marks
| Command | Description |
|---|---|
ma | Set mark a at cursor |
`a | Jump to mark a (exact position) |
'a | Jump to mark a (line start) |
:marks | List all marks |
`. | Jump to last change |
`` `` | Jump to position before last jump |
File & Buffer Commands
| Command | Description |
|---|---|
:w | Save |
:w file | Save as |
:q | Quit |
:q! | Quit without saving |
:wq / :x / ZZ | Save and quit |
:e file | Open file |
:bn / :bp | Next / previous buffer |
:ls | List buffers |
:bd | Close buffer |
Windows & Tabs
| Command | Description |
|---|---|
:sp file | Horizontal split |
:vsp file | Vertical split |
Ctrl+w h/j/k/l | Navigate between windows |
Ctrl+w = | Equal size windows |
Ctrl+w _ | Maximize height |
Ctrl+w | | Maximize width |
:tabnew file | New tab |
gt / gT | Next / previous tab |