Vim Cheatsheet
Modes (most important concept)
| Mode |
Key |
Purpose |
| Normal |
Esc |
Navigate, manipulate text |
| Insert |
i |
Insert text |
| Visual |
v |
Select text |
| Visual Line |
V |
Select lines |
| Visual Block |
Ctrl+v |
Column/block selection |
| Command |
: |
Run commands |
Open / Exit / Save
| Action |
Command |
| Open file |
vim file.txt |
| Save |
:w |
| Save & quit |
:wq |
| Quit |
:q |
| Quit without saving |
:q! |
| Save all & quit |
:wqa |
Cursor Movement (Normal mode)
Basic
| Key |
Move |
| h j k l |
left / down / up / right |
| w |
next word |
| b |
previous word |
| 0 |
line start |
| ^ |
first non-blank |
| $ |
line end |
Fast movement
| Key |
Move |
| gg |
file start |
| G |
file end |
| 5G |
go to line 5 |
| Ctrl+u |
half page up |
| Ctrl+d |
half page down |
Insert Mode
| Key |
Action |
| i |
insert before cursor |
| a |
insert after cursor |
| I |
insert at line start |
| A |
insert at line end |
| o |
new line below |
| O |
new line above |
| Esc |
back to normal |
Editing Text
Delete
| Command |
Meaning |
| x |
delete char |
| dd |
delete line |
| dw |
delete word |
| d$ |
delete to end of line |
| d0 |
delete to line start |
Copy / Paste
| Command |
Meaning |
| yy |
yank (copy) line |
| yw |
yank word |
| p |
paste after |
| P |
paste before |
Change
| Command |
Meaning |
| cw |
change word |
| cc |
change line |
| c$ |
change to line end |
Undo / Redo
| Command |
Action |
| u |
undo |
| Ctrl+r |
redo |
Visual Mode (Selection)
| Key |
Action |
| v |
character select |
| V |
line select |
| Ctrl+v |
block select |
| y |
copy selection |
| d |
delete selection |
| > / < |
indent / unindent |
Search & Replace
Search
| Command |
Action |
| /word |
search forward |
| ?word |
search backward |
| n |
next match |
| N |
previous match |
Replace
Flags:
| Flag |
Meaning |
| g |
global |
| c |
confirm |
| i |
case-insensitive |
Example:
File Navigation
| Command |
Action |
| :e file |
open file |
| :ls |
list buffers |
| :b2 |
switch buffer |
| :bd |
close buffer |
Windows & Splits
| Command |
Action |
| :split |
horizontal split |
| :vsplit |
vertical split |
| Ctrl+w w |
switch window |
| Ctrl+w q |
close window |
| Ctrl+w = |
equal sizes |
Tabs
| Command |
Action |
| :tabnew |
new tab |
| gt |
next tab |
| gT |
previous tab |
| :tabclose |
close tab |
| Command |
Action |
| >> / << |
indent line |
| = |
auto-format |
| gg=G |
format entire file |
Useful Power Moves (Must-Know)
| Command |
Why it's great |
| . |
repeat last action |
| ci" |
change inside quotes |
| di( |
delete inside parentheses |
| % |
jump between brackets |
| * |
search word under cursor |
Macros (Automation)
| Command |
Action |
| qa |
record macro a |
| (do stuff) |
perform actions to record |
| q |
stop recording |
| @a |
play macro |
| @@ |
repeat last macro |
Vim Grammar (Golden Rule)
[number] + operator + motion
Examples:
3dw -> delete 3 words
dG -> delete to end of file
y$ -> copy to line end