Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Vim Editor Commands Reference cheat sheet - grade 9-12

Click image to open full size

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. 1 You are in Normal mode at the top of a file. What command moves the cursor down 12 lines?
  2. 2 Write the Vim command that saves the current file and quits Vim in one step.
  3. 3 A file contains the word color 8 times. What command replaces every color with colour in the whole file?
  4. 4 Why does Vim use separate modes for inserting text and running editing commands?

Understanding Vim Editor Commands Reference

Vim works best when you treat each command as a small sentence. Many edits combine an action with a movement. A delete action can act on one character, a word, a sentence, or everything up to a chosen position.

This idea is more useful than memorising long lists. A number placed before a command usually repeats it. For example, a movement can travel several words at once, while an edit can affect several lines.

The cursor marks a position between characters, which can feel unusual at first. Watch where it sits before making a change, especially near brackets, quotes, or the end of a line.

Visual mode is useful when an edit is easier to see than to describe with movements. It can select characters, whole lines, or a rectangular block. Block selection is valuable for code because it can add or remove the same indentation across many lines.

Indentation matters in languages such as Python, where spacing changes the program structure. In other languages, clean indentation still makes nested loops and conditionals easier to read. Vim stores copied and deleted text in registers.

This means a deletion may replace the text you planned to paste later. When working on a large change, copy important text first or use a named register so it stays available.

Searching in Vim is more than finding one exact word. A search pattern can match part of an identifier, repeated text, or a group of similar lines. This helps when a variable has been used in many places.

Be careful with short search terms because they can match inside longer names or comments. Replacement commands can change many matches quickly, so they need extra care. A confirmation option lets you inspect each proposed replacement before accepting it.

This is a good habit when renaming a function or correcting a repeated spelling mistake. After a search, the current match remains part of Vim's state, so later commands may behave differently than expected if you forget what was last searched.

Files in Vim are held in buffers. A buffer is the version of a file currently open in the editor. Saving writes that buffer to storage, while quitting closes the editing session.

Vim warns before closing a buffer with unsaved changes because losing work is easy during fast command use. In a terminal, it is common to open Vim, make a small edit, save, run a program, then return to the editor. Build a routine for this cycle.

Make one change, save it, run the code, read any error message, then fix the relevant line. Use undo freely while learning.

It is safer to test a command on a small practice file than on a long assignment. Speed comes later from accuracy, awareness of the current mode, and steady habits.