This cheat sheet covers the most useful Vim editor commands for students learning to write and edit code efficiently. Vim is a keyboard-based text editor, so knowing its modes and command patterns is essential. A clear reference helps students avoid getting stuck, move faster through files, and edit code with confidence.
It is designed as a printable guide for quick use during programming assignments.
Key Facts
- Press i to enter Insert mode before typing new text into the file.
- Press Esc to return to Normal mode before running movement, editing, search, or file commands.
- Use h, j, k, and l to move left, down, up, and right by one character or line.
- Use w to move to the next word, b to move back one word, and 0 or $ to move to the start or end of a line.
- Use dd to delete the current line, yy to copy the current line, and p to paste after the cursor.
- Use u to undo the last change and Ctrl+r to redo an undone change.
- Use /text to search forward for text, n to go to the next match, and N to go to the previous match.
- Use :w to save, :q to quit, :wq to save and quit, and :q! to quit without saving.
Vocabulary
- Normal Mode
- The Vim mode used for moving the cursor, deleting text, copying text, searching, and entering commands.
- Insert Mode
- The Vim mode used for typing and inserting text into a file.
- Visual Mode
- The Vim mode used to select text before copying, deleting, or changing it.
- Command-Line Mode
- The Vim mode opened with : where students save files, quit Vim, and run replace commands.
- Yank
- Vim's word for copying text without removing it from the file.
- Buffer
- The in-memory version of a file that Vim is currently editing.
Common Mistakes to Avoid
- Typing text while still in Normal mode, which is wrong because keys like d, y, and p run commands instead of inserting letters.
- Forgetting to press Esc before saving or quitting, which is wrong because :w and :q only work from Normal mode.
- Using :q when the file has unsaved changes, which is wrong because Vim protects the file and will not quit until changes are saved or discarded.
- Confusing dd and yy, which is wrong because dd deletes a line while yy copies a line without removing it.
- Running a replace command without checking the pattern, which is wrong because :%s/old/new/g can change every matching word in the entire file.
Practice Questions
- 1 You are in Normal mode at the top of a file. What command moves the cursor down 12 lines?
- 2 Write the Vim command that saves the current file and quits Vim in one step.
- 3 A file contains the word color 8 times. What command replaces every color with colour in the whole file?
- 4 Why does Vim use separate modes for inserting text and running editing commands?