v%if the cursor is on the starting/ending parenthesisvibif the cursor is inside the parenthesis blockvi"for double quotesvi'for single quotesvi{ / viBfor curly blockgvreselect last visual selection
==reselect last visual selection=in visual mode, indents the selected blockgg=Ggo to beginning of the buffer (gg) and indents (=) until the end of buffer (G)<and>indents a block (in visual mode) to left or right. Press '.' to repeat last indenting and 'u' to undo
*and # search for the word under the cursor forward/backwardwto the next wordWto the next space-separated wordb/eto the begin/end of the current word. (B / E for space separated only)gg/Gjump to the begin/end of the file%jump to the matching { .. } or ( .. ), etc...{/}jump to next paragraph'.jump back to last edited linenGjump to line nLjump to the bottom of the screen ("low")Hjump to the top of the screen ("high")Mjump to the middle of the screen ("middle")C-ojump backC-ijump forwardztmove this line to the top of the screen ("top")zbmove this line to the bottom of the screen ("bottom")zzmove this line to the middle of the screen ("ziddle?")
/search_patternfind next match. Examples "/function" or "/\d{2}-\d{2}-\d{2}" to locate some date like "1981-06-13"?search_patternfind match backwardnrepeat the next '/' or '?' commandNsame as 'n' but in reverse direction%s/text/other/replace 'text' by 'other' in the whole document (some commands accepts ranges and % stands for the whole document range - see ':h range'):s/text/other/replace 'text' by 'other' in the current line. Actually, any character can be used instead of '/', like 's.7/11/2010.11/7/2010.':'<,'>s/text/other/replace 'text' by 'other' in the last visual selection. '< and '> are the markers for the beginning and ending of the visual selection. Pressing ':' while on visual mode, these markers are automatically inserted in the command line.&repeat last substitution command- Multiple files
# bad
arr = Array.new
hash = Hash.new
# good
arr = []
hash = {}
Iinsert at the begina/Aappend to next / append to endo/Oopen a new line after/before the currentv/Vvisual mode (to select text!)Shift+Rreplace textCchange remaining part of linedddelete current line (actually, moves it to Vim internal clipboard)Ddelete until the end of the linedwdelete from current cursor until the end of the word under cursordiwdelete inner word (the entire word under the cursor)dbdelete until the beginning of the word or a word backward if the cursor is already in the beginning of some wordds',ds",ds{,ds[,ds(delete surrounds ('', "", {}, (), [])dstdelete surrounding tagdi',di",di{,di[,di(delete content inside the given surroundda',da",da{,da[,da(delete all content of the given surround, including the surround charactersditdelete inner tag contentcswork likedsbut replacing the surround instead of deleting them. For instance, ci"' will turn "text" into 'text'yss*apply surround around the entire line. Ex.yss'will apply an apostrophe around the line, whileysswill surround the line with a div tag.s*adds a surround while on visual mode (click and drag with mouse or press 'v' to ender visual mode and use the movement commands)ysapplies surround around the region described by the movement command. Ex. With cursor under "word"ysiwresults inwordc,cw,ciw,cb,ci*works like the delete commands but finish the command on insert mode (c stands for change)c,cw,ciw,cb,ci*works like the delete commands but finish the command on insert mode (c stands for change)\ctoggle line (or block in visual mode) commentingggdG[d]eletes entire buffer - from beginning [gg] to end [G] of the document
cWchange till end of word3cWchange 3 wordsBcWto begin of full word, change full wordciWchange inner wordci"change inner between ".."ci(change text between ( .. )4dddelete 4 lines3xdelete 3 characters3ssubstitute 3 characters
:set foldmethod=syntaxfold by syntax definitions:set foldmethod=indentold by indentationzcclose the current foldzoopen the current foldzMclose all foldszropen one level of foldszRopen all foldszjmove to the next foldzkmove to the previous foldzmclose one level of foldszndisable foldingzNre-enable folding
rreplace one character (e.g. rd replaces the current char with d)~changes caseCtrl+A/Ctrl+Xincrements/decrements a number.repeat last command (a simple macro)=indent line (specify a range, or use visual mode)
bufdorefresh all files in buffer from disk
w !sudo tee %
- Press
q[key]to start recording - Then hit
qto stop recording - The macro can be played with
@[key]