The Vim Cheatsheet
A comprehensive guide to the most useful Vim commands. Because if you're going to use @iusevimbtw.com, you'd better know how to use it.
Basic Commands
Command reference for Vim users of all levels
| Command | Description |
|---|---|
| i | Enter insert mode |
| Esc | Return to normal mode |
| :w | Save file |
| :q | Quit Vim |
| :wq | Save and quit |
| :q! | Quit without saving |
| h, j, k, l | Move cursor left, down, up, right |
Text Manipulation
Command reference for Vim users of all levels
| Command | Description |
|---|---|
| u | Undo |
| Ctrl+r | Redo |
| dd | Delete line |
| yy | Copy (yank) line |
| p | Paste after cursor |
| P | Paste before cursor |
| dw | Delete word |
| cw | Change word |
Search and Replace
Command reference for Vim users of all levels
| Command | Description |
|---|---|
| / | Search forward |
| ? | Search backward |
| n | Next search result |
| N | Previous search result |
| :%s/old/new/g | Replace all occurrences of "old" with "new" |
| :s/old/new/g | Replace all occurrences of "old" with "new" on current line |
Advanced Commands
Command reference for Vim users of all levels
| Command | Description |
|---|---|
| gg | Go to beginning of file |
| G | Go to end of file |
| ZZ | Save and quit |
| ZQ | Quit without saving |
| :e filename | Open file |
| :split | Split window horizontally |
| :vsplit | Split window vertically |
| Ctrl+w w | Switch between windows |
Visual Mode
Command reference for Vim users of all levels
| Command | Description |
|---|---|
| v | Enter visual mode (character-wise) |
| V | Enter visual mode (line-wise) |
| Ctrl+v | Enter visual mode (block-wise) |
| y | Yank (copy) selected text |
| d | Delete selected text |
| c | Change selected text |
| > | Indent selected text |
| < | Un-indent selected text |
Exit Vim: The Ultimate Challenge
According to legend, some developers are still trying to figure out how to exit Vim. Here's the sacred knowledge:
const exitVim = () => {
// Press Escape to make sure you're in normal mode
const saveChanges = true;
if (saveChanges) {
return ":wq"; // Write and quit
} else {
return ":q!"; // Force quit, discard changes
}
};
// But remember, you can check in any time you like, but you can never leave