Modes:

  • Normal Mode (Esc): Used for navigation and commands.
  • Insert Mode (i): Used for inserting or editing text.
  • Visual Mode (v): Used for selecting text.

Navigation:

  • h, j, k, l: Move left, down, up, and right respectively.
  • 0 (zero): Move to the beginning of the line.
  • ^ (caret): Move to the first non-whitespace character of the line.
  • $: Move to the end of the line.
  • G: Move to the end of the file or to a specified line number (e.g., :12).

Editing:

  • i: Enter Insert mode before the cursor.
  • I: Enter Insert mode at the beginning of the line.
  • a: Enter Insert mode after the cursor.
  • A: Enter Insert mode at the end of the line.
  • o: Open a new line below the current line.
  • O: Open a new line above the current line.
  • x: Delete the character under the cursor.
  • dd: Delete the current line.
  • yy: Copy (yank) the current line.
  • p: Paste the yanked or deleted text after the cursor.
  • u: Undo the last change.
  • Ctrl + r: Redo the last undone change.

Visual Mode:

  • v: Enter Visual mode to select characters.
  • V: Enter Visual mode to select whole lines.
  • Ctrl + v: Enter Visual block mode to select a block of text.

Search and Replace:

  • /pattern: Search forward for the specified pattern.
  • ?pattern: Search backward for the specified pattern.
  • n: Move to the next occurrence of the search pattern.
  • N: Move to the previous occurrence of the search pattern.
  • :s/old/new: Replace the first occurrence of ‘old’ with ‘new’ in the current line.
  • :s/old/new/g: Replace all occurrences of ‘old’ with ‘new’ in the current line.
  • :%s/old/new/g: Replace all occurrences of ‘old’ with ‘new’ in the entire file.

Saving and Quitting:

  • :w: Save changes.
  • :q: Quit (close) the editor.
  • :wq or :x: Save changes and quit.
  • :q!: Quit without saving.

Miscellaneous:

  • Ctrl + g: Show file information and cursor position.
  • :set number: Display line numbers.
  • :set nonumber: Hide line numbers.
  • :help command: Open help for a specific command.