You don’t need to memorize a massive manual to be productive…you just need the essentials.
Bookmark this cheatsheet to build your muscle memory, and soon you’ll wonder how you ever worked without it.
Vim Essential Cheatsheet
Navigation
| h j k l | Left, Down, Up, Right |
| w / b | Next word / Previous word |
| 0 / $ | Start of line / End of line |
| gg / G | First line / Last line |
| Ctrl+d | Jump down half page |
| Ctrl+u | Jump up half page |
Editing
| i / a | Insert before / Append after cursor |
| o / O | Open new line below / above |
| x | Delete character under cursor |
| dd | Delete (cut) entire line |
| yy | Yank (copy) entire line |
| p / P | Paste after / before cursor |
| u | Undo |
| Ctrl+r | Redo |
Search & Replace
| /pattern | Search forward for pattern |
| ?pattern | Search backward for pattern |
| n / N | Next / Previous search match |
| :%s/old/new/g | Replace all ‘old’ with ‘new’ in file |
| :%s/old/new/gc | Replace all with confirmation |
File Operations
| :w | Save (write) file |
| :q | Quit (fails if unsaved) |
| :wq or 😡 | Save and quit |
| :q! | Force quit (discard changes) |
| :e file | Open a file to edit |
Vim “Magic”: Common Workflows
1. Change text inside quotes or brackets
Scenario: You want to replace a URL inside an HTML tag: href=”https://old-url.com”
Action: Place your cursor anywhere inside the quotes and type ci” (Change Inner Quotes). It deletes the URL and puts you right into Insert mode to type the new one. This also works with ci( for parentheses or ci{ for curly braces.
2. Auto-indent an entire file
Scenario: You just pasted a block of code and the indentation is completely broken.
Action: Type gg=G.
(gg jumps to the top, = is the format command, and G tells it to format all the way to the bottom).
3. The magical “Dot” command
Scenario: You need to add a semicolon to the end of 5 different lines.
Action: On the first line, type A to jump to the end and insert, type ;, then press Esc. Now, move your cursor to the next line and simply press . (period). Vim repeats your last edit perfectly.
4. Commenting out multiple lines (Visual Block)
Scenario: You want to add a # to the beginning of 10 lines of code.
Action:
1. Press Ctrl+v to enter Visual Block mode.
2. Use j to select the first column of the lines you want to comment.
3. Press Shift+i (Insert at beginning).
4. Type #.
5. Press Esc and watch the # magically appear on all selected lines.
2. Use j to select the first column of the lines you want to comment.
3. Press Shift+i (Insert at beginning).
4. Type #.
5. Press Esc and watch the # magically appear on all selected lines.
5. Jump straight to an error line
Scenario: Your compiler or server log tells you there is an error on line 142.
Action: In Normal mode, just type 142G. You will instantly jump to line 142.