If you work with Linux, servers, or programming, Vim is almost impossible to avoid. It’s powerful, fast, and available on nearly every Unix-like system. But the learning curve can feel steep at first.
This Vim cheat sheet gives you the most useful commands in a simple and practical format. You’ll learn how to open files, navigate quickly, edit text efficiently, and save or quit without frustration.
Table of Contents
Quick Vim Commands Summary
| Task | Command | What It Does |
|---|---|---|
| Open file | vim file.txt | Open a file in Vim |
| Enter insert mode | i | Start typing before cursor |
| Append text | a | Insert text after cursor |
| Save file | :w | Write changes |
| Save & quit | :wq | Save and exit |
| Quit without saving | :q! | Exit and discard changes |
| Delete line | dd | Delete current line |
| Copy line | yy | Copy current line |
| Paste | p | Paste after cursor |
| Undo | u | Undo last action |
| Redo | Ctrl + r | Redo last undo |
| Search | /word | Search forward |
| Replace | :%s/old/new/g | Replace in entire file |
| Go to start | gg | Jump to first line |
| Go to end | G | Jump to last line |
Opening Files in Vim
The most common way to open a file is:
vim filename.txt
Open multiple files:
vim file1.txt file2.txt
Open a file and jump to a line:
vim +25 file.txt
Useful when reading logs or debugging code.
Vim Modes (The Key Concept)
Understanding Vim modes makes everything easier.
| Mode | Purpose |
|---|---|
| Normal mode | Navigate and run commands |
| Insert mode | Type text |
| Visual mode | Select text |
Return to normal mode anytime:
Esc
Enter insert mode:
i
Other insert options:
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
| Command | Behavior |
|---|---|
i | insert before cursor |
a | insert after cursor |
o | new line below |
O | new line above |
Moving Around in Vim
Navigation is where Vim becomes powerful.
Basic movement
| Key | Move |
|---|---|
h | left |
j | down |
k | up |
l | right |
Faster navigation
| Command | Result |
|---|---|
w | next word |
b | previous word |
0 | start of line |
$ | end of line |
Jump in file
| Command | Result |
|---|---|
gg | top of file |
G | bottom of file |
:50 | go to line 50 |
Editing Text
Editing text is extremely efficient once you know a few commands.
Delete
| Command | Action |
|---|---|
x | delete character |
dd | delete line |
dw | delete word |
Copy and Paste
| Command | Action |
|---|---|
yy | copy line |
yw | copy word |
p | paste after |
P | paste before |
Example workflow:
yy
p
Duplicate a line instantly.
Undo and Redo
Everyone makes mistakes.
| Command | Action |
|---|---|
u | undo |
Ctrl + r | redo |
Undo multiple changes by pressing u repeatedly.
Searching in Vim
Search forward:
/word
Search backward:
?word
Next match:
n
Previous match:
N
Example:
/error
Jump through every occurrence of “error” in a log file.
Find and Replace
Replace text in Vim using this command:
:%s/old/new/g
Explanation:
| Part | Meaning |
|---|---|
% | entire file |
s | substitute |
g | all matches |
Replace only in current line:
:s/old/new/g
Ask before replacing:
:%s/old/new/gc
Saving and Exiting
The most famous Vim commands:
| Command | Meaning |
|---|---|
:w | save file |
:q | quit |
:wq | save and quit |
:q! | quit without saving |
Shortcut:
ZZ
Save and exit quickly.
Visual Mode (Selecting Text)
Enter visual mode:
v
Select lines:
V
Block selection:
Ctrl + v
Useful for column editing or copying blocks of code.
Bonus: Speed Tricks
These small tricks make Vim feel magical.
Duplicate line:
yy
p
Join lines:
J
Repeat last command:
.
Example:
dw
.
.
.
Delete multiple words instantly.
Final Thoughts
Vim looks intimidating at first, but learning just a few core commands makes it extremely productive.
Start with:
- navigation
- insert mode
- delete / copy
- search
- save and quit
Once these become muscle memory, editing files in the terminal becomes much faster than using a mouse.
Vim Cheat Sheet FAQ
1. How do I exit Vim if I’m stuck?
Press Esc then type :q! and hit Enter.
2. How do I save a file in Vim?
Use :w to write the file to disk.
3. What is the fastest way to delete a line in Vim?
Use dd.
4. How do I search for text in Vim?
Type /word then press Enter.
5. Why do developers prefer Vim?
Because it allows extremely fast keyboard-based editing once learned.




