A Vim Cheatsheet

All of these works on VS Code flavored Vim which is amaze.

Opening, Saving and Closing Files:

  • :e filename - Open filename
  • :w - Save the current file
  • :wq or :x - Save and quit
  • :q - Quit
  • :q! - Quit without saving

Navigation:

  • h - Move left
  • j - Move down
  • k - Move up
  • l - Move right
  • w - Move to the start of the next word
  • b - Move to the start of the previous word
  • 0 - Move to the start of the line
  • $ - Move to the end of the line
  • gg - Move to the first line
  • G - Move to the last line

Editing:

  • i - Insert mode
  • a - Append mode
  • o - Open a new line below the current line
  • O - Open a new line above the current line
  • u - Undo
  • Ctrl + r - Redo

Cutting, Copying and Pasting:

  • dd - Delete (cut) a line
  • yy - Yank (copy) a line
  • p - Paste below the cursor
  • P - Paste above the cursor

Searching:

  • /pattern - Search for pattern
  • n - Find next occurrence
  • N - Find previous occurrence
  • :%s/old/new/g - Replace all occurrences of old with new

Split Windows:

  • :sp filename - Split window and open filename
  • :vsp filename - Split window vertically and open filename
  • Ctrl + w followed by an arrow key - Move between split windows

Code Navigation:

  • gd - Go to definition
  • Ctrl + o - Move back to previous location
  • Ctrl + i - Move forward to the next location