Skip to content

Instantly share code, notes, and snippets.

@jaawerth
Forked from jessedearing/vim cheatsheet.md
Created November 4, 2016 05:51
Show Gist options
  • Save jaawerth/81807541b5ee4d6d822b16bb5752dc11 to your computer and use it in GitHub Desktop.
Save jaawerth/81807541b5ee4d6d822b16bb5752dc11 to your computer and use it in GitHub Desktop.
Vim Cheatsheet

#Vim Cheat Sheet

  • gqip - Reformats paragraph to textwidth
  • gq - Reformats selection
  • :Tab /= - Equally spaces based on the = symbol (requires Tabular vim plugin)
  • :setf language - Changes current language
  • :set language=language - Changes current language
  • <C-a> - Increments the number under the cursor
  • <C-x> - Decrements the number under the cursor
  • ~ - Toggles case and moves to next character in normal mode
  • gU<movement> - Uppercases
  • gu<movement> - Lowercases
  • <visual>U - Uppercases in Visual mode
  • <visual>u - Uppercases in Visual mode
  • <C-o> - While in insert mode lets you run a single command-mode command and returns you back to insert mode
  • :cq - Quits with an error code. (Good for canceling a SCM commit)

##Sed-style Replacements

  • s/<sed regex>/<replacement>/<flags>
    • <flags> - Can be a combintion of g for global (all occurances in a line, i to ignore case, and c to confirm each substitution

###Sed-style Regex

  • \? - 0 or 1
  • * - 0 or more
  • \+ - Matches one or more
  • \( \) - Captured grouping (can be used later in replacement with \1, \2, etc.
  • \%( \) - Non capturing group
  • ^ and $ - Beginning and end of line respectively

##Surround plugin

  • ys<motion or text><char to wrap> - Surrounds the text in the motion (Example: w for to the next word or $ to the end of the line) with the character, HTML tag, etc.
  • cs<old char><new char> - Changes the surrounding character
  • cst<html tag> - Changes an html tag from the current to a new one
  • ctrl-s - Adds a surrounding in insert mode

##Fugitive (Git extensions)

  • :Gdiff - Diffs file with current version in repository
  • :Gw - Saves and git adds
  • :Gco or :Gcommit - Commits

Three Way Diff

3 way reconciliation

##Ack.vim

o    to open (same as enter)
go   to preview file (open but maintain focus on ack.vim results)
t    to open in new tab
T    to open in new tab silently
v    to open in vertical split
gv   to open in vertical split silently
q    to close the quickfix window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment