Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2016 11:52
Show Gist options
  • Save ummahusla/98b381e0355e43973085 to your computer and use it in GitHub Desktop.
Save ummahusla/98b381e0355e43973085 to your computer and use it in GitHub Desktop.
Vim Cheat Sheet


Vim has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for "colon" commands which execute when you press the ruturn key.


  • :x Exit, saving changes
  • :q Exit as long as there have been no changes
  • ZZ Exit and save changes if any have been made
  • :q! Exit and ignore any changes

Inserting Text

  • i Insert before cursor
  • I Insert before line
  • a Append after cursor
  • A Append after line
  • o Open a new line after current line
  • O Open a new line before current line
  • r Replace one character
  • R Replace many characters


  • h Move left
  • j Move down
  • k Move up
  • l Move right
  • w Move to next word
  • W Move to next blank delimited word
  • b Move to the beginning of the word
  • B Move to the beginning of blank delimted word
  • e Move to the end of the word
  • E Move to the end of Blank delimited word
  • ( Move a sentence back
  • ) Move a sentence forward
  • { Move a paragraph back
  • } Move a paragraph forward
  • 0 Move to the begining of the line
  • H Move to top of screen
  • M Move to middle of screen
  • L Move to botton of screen
  • % Move to associated ( ), { }, [ ]

Search for strings

  • /str Search forward for string
  • ?str Search back for string
  • n Search for next instance of string
  • N Search for previous instance of string

Deleting Text

Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:

  • x Delete character to the right of cursor
  • X Delete character to the left of cursor
  • D Delete to the end of the line
  • dd Delete current line
  • :d Delete current line


The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).

  • :s/pattern/string/flags Replace pattern with string according to flags. (Example: :%s/foo/bar/. Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.)
  • g Flag - Replace all occurrences of pattern
  • c Flag - Confirm replaces.
  • & Repeat last :s command


  • :w file Write to file
  • :r file Read file in after line
  • :n Go to next file
  • :p Go to previos file
  • :e file Edit file
  • !!program Replace line with output from program


  • ~ Toggle upp and lower case
  • J Join lines
  • . Repeat last text-changing command
  • u Undo last change
  • U Undo all changes to line
Copy link

chemzqm commented Feb 18, 2016

Here's some key shortcut I use a lot with:

  • <C-^> switch current buffer with an alternative one
  • zi toggle fold/unfold of current buffer
  • gd jump to definition
  • zz make current line center of the screen

Copy link

  • y Yank/Copy a marked text.
  • yy Yank/Copy a line.

Copy link

sheeit commented Feb 20, 2016

  • $ Move to the end of the line.

Copy link

  • shift+d Delete characters until end of the line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment