Essential Vim commands
Modes, movement, editing and search-and-replace: enough to survive in Vim — and get back out without breaking your file.
Modes
| Key | Effect |
|---|---|
Esc |
Back to normal mode |
i |
Insert before the cursor |
a |
Insert after the cursor |
v |
Visual mode (character selection) |
Shift + v |
Visual line mode |
: |
Command mode |
Moving around
| Key | Effect |
|---|---|
h j k l |
Left, down, up, right |
w / b |
Next / previous word |
0 / $ |
Start / end of line |
gg / G |
Start / end of file |
:42 |
Go to line 42 |
Editing
| Key | Effect |
|---|---|
dd |
Delete the line |
yy |
Copy (yank) the line |
p / P |
Paste after / before |
u / Ctrl + r |
Undo / redo |
. |
Repeat the last change |
x |
Delete the character under the cursor |
Search and replace
/pattern search downward n / N next / previous match :%s/old/new/g replace everywhere in the file :%s/old/new/gc replace with confirmation
Saving and quitting
:w save :q quit :wq save and quit :q! quit without saving
Stuck in Vim? Esc then :q! + Enter quits without saving anything.
Multiple files and windows
:e file.txt open another file :sp file.txt split horizontally :vsp file.txt split vertically Ctrl + w then w switch between windows :bn / :bp next / previous buffer
The count + command combination
Almost every Vim command accepts a number in front to repeat it:
3dd delete 3 lines 5j move down 5 lines 2yy copy 2 lines 10x delete 10 characters
This "count + verb + motion" logic (e.g. d2w = delete 2 words) is at the heart of Vim's philosophy: composing commands rather than memorising each one individually.
Thanks for the feedback!