Introduction: Why Vim Still Matters
If you have ever found yourself stuck in the Vim editor, desperately mashing the keyboard and Googling "how to exit Vim," you are definitely not alone. Vim's steep learning curve is legendary, but so is its power.
While modern code editors with graphical interfaces are great, mastering Vi and Vim remains a superpower for software engineers, sysadmins, and Linux enthusiasts. It allows you to edit files directly on remote servers, tweak configurations at lightning speed, and completely ditch the mouse to keep your hands on the keyboard.
Yes, the learning curve is steep, but the productivity payoff is massive. To help you master this legendary editor, we have compiled the ultimate, human-readable Vim cheat sheet. Bookmark this page so you never get stuck again!
1. The Absolute Basics: Quick Reference
If you only memorize a handful of commands today, make sure it is these. These are the bread and butter of your daily workflow.
i– Enter Insert Mode (start typing)ESC– Return to Command Mode:wqorZZ– Save and quit:q!– Quit without saving (force quit)dd– Delete the current lineyy– Copy (yank) the current linep– Pasteu– Undo your last action/text– Search for "text"
2. Opening & File Operations
Before you can edit, you need to know how to handle your files and navigate the terminal environment.
| Command | Description |
|---|---|
vi filename | Open or create a file |
vi -r filename | Recover a crashed file |
vi +num file | Open file directly at a specific line number |
:w filename | Save as a new filename |
:e filename | Edit another file without leaving Vim |
:!ls | Run a shell command (like 'ls') from inside Vim |
4. Editing: Inserting, Deleting & Changing
Once you are at the right location in your code, you need to manipulate the text efficiently.
| Command | Description |
|---|---|
I / A | Insert text at the absolute beginning (I) or end (A) of the line |
o / O | Open a new blank line below (o) or above (O) the cursor |
dw | Delete the current word |
d$ or D | Delete everything from the cursor to the end of the line |
cw | Change word (Deletes the word and drops you into Insert Mode) |
r / R | Replace a single character (r) or enter overwrite mode (R) |
~ | Toggle uppercase/lowercase of the letter under the cursor |
5. Search and Replace
Vim's search and replace capabilities are incredibly powerful, using Regex (Regular Expressions) to find exactly what you need.
| Command | Description |
|---|---|
/string | Search forward for "string" |
n / N | Find the next occurrence (n) or previous occurrence (N) |
* | Instantly search for the exact word currently under your cursor |
:s/old/new/g | Replace all instances of "old" with "new" on the current line |
:%s/old/new/g | Replace all instances throughout the entire file |
:%s/old/new/gc | Replace globally, but ask for confirmation before each change |
6. Visual Mode & Buffers
Visual mode allows you to highlight blocks of code, while buffers let you juggle multiple files at once.
| Command | Description |
|---|---|
v / V | Enter Visual Character mode (v) or Visual Line mode (V) |
Ctrl+v | Visual Block mode (amazing for editing columns of text/code) |
> / < | Indent the selected text right (>) or left (<) |
:ls | List all currently open buffers (files) |
:bn / :bp | Switch to the next (:bn) or previous (:bp) buffer |
7. Configuration Commands (:set)
Customize how Vim behaves. You can type these during a session, or add them to your .vimrc file to make them permanent.
:set nu– Show line numbers:set ic– Ignore case in searches:set ai– Turn on auto-indentation:set syntax on– Turn on syntax highlighting for code
Your Next Steps: Practice!
You cannot learn Vim just by reading a cheat sheet. The muscle memory comes from doing.
Try this exercise today: Open your terminal and type vimtutor. It is a brilliant, interactive 30-minute lesson built directly into Vim that will force you to practice the commands above.
What is your favorite Vim shortcut? Let us know in the comments below!
Frequently Asked Questions (FAQ)
1. How do I exit Vim if I'm stuck?
Press ESC to ensure you're in Command Mode, then type :q! to quit without saving, or :wq to save and quit. Alternatively, ZZ (capital Z twice) saves and quits.
2. What's the difference between Vi and Vim?
Vi is the original Unix text editor. Vim (Vi Improved) is a modern, enhanced clone with features like syntax highlighting, multi-level undo, and a powerful plugin system. Most systems alias vi to vim.
3. How do I undo and redo in Vim?
Use u to undo the last change. To redo (undo an undo), press Ctrl+r.
4. How do I copy, cut, and paste in Vim?
Copy (yank): yy (line) or yw (word). Cut (delete): dd (line) or dw (word). Paste: p (after cursor) or P (before cursor).
5. How do I show line numbers in Vim?
Type :set nu (or :set number) in Command Mode. To make it permanent, add set number to your ~/.vimrc file.
6. How can I learn Vim quickly?
Run vimtutor in your terminal. It's an interactive 30-minute tutorial that comes with Vim and teaches the basics through hands-on exercises.
Comments