#Vim Cheat Sheet
gqip
- Reformats paragraph to textwidthgq
- 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 modegU<movement>
- Uppercasesgu<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 ofg
for global (all occurances in a line,i
to ignore case, andc
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 charactercst<html tag>
- Changes an html tag from the current to a new onectrl-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
##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