This is an old revision of the document!


Vim Cheat Sheet

Overview

Vim is a powerful, lightweight text editor which is primarily keyboard driven. Because it is keyboard-driven its power is often not fully realized. This cheat sheet will explore some of vim's features as well as serve as a quick reference.

Vim has three main modes.

  • Navigation mode - The default mode is a navigation mode used to move around the document.
  • Edit mode - Using an editing command puts vim into an edit mode where everything typed is either inserted or overwritten into the document. ESC will exit edit mode.
  • Highlight mode - This similar to navigation mode but everything from the first position of the cursor to the current position is selected.

In navigation mode, the following can be used to move around

  • < h \/ j k ^ l > - Move by one letter - : h-left, l-right, j-down, k-up
  • w b e - Move by words - w - next word, b - prev word, e - end of word
  • W B E Move by sequences of non-blanks (Words) - W - next Word, B - prev Word, E - end of Word
  • f F - find character, Find character backwards
  • t T - stop before next/last instance of character

Basic Editing

  • i I - insert / insert at start of line
  • a A - append, append to end of line
  • R - overwrite
  • dd cc - delete or change line (enter insert mode)
  • d c [n] X - delete or change where X is a navigation command eg d2w. Change enters insert mode.
  • o O - open new line for inserting below or above
  • x s - delete character, delete character and start inserting

Copying & Pasting

  • d|y [n] X - delete or yank text into buffer
  • dd yy - delete or yank line into buffer
  • p P - paste after or before
  • “[a-z] - used before delete/yank/paste to specify a register
  • ”[A-Z] - used before delete/yank to append to previous contents of register
  • “* ”+ - Use system clipboard as register

Searching & Bookmarks

  • / ? - Start incremental search forwards or backwards
  • n N - next match forwards or backwards
  • * # - Search for next/previous instance of word under cursor
  • m[a-z] - set a bookmark
  • `[a-z] - jump to bookmark
  • '[a-z] - jump to first non-blank on bookmarked line
  • [A-Z]] - global bookmarks (not buffer-specific)
  • . - bookmark of last modification

Assorted

  • q[a-z] - start recording macro
  • qq - stop recording macro
  • @[a-z] - play macro
  • @@ - play last played macro
Recent changes RSS feed Creative Commons License Donate Minima Template by Wikidesign Driven by DokuWiki