v%
if the cursor is on the starting/ending parenthesisvib
if the cursor is inside the parenthesis blockvi"
for double quotesvi'
for single quotesvi{ / viB
for curly blockgv
reselect last visual selection
==
reselect last visual selection=
in visual mode, indents the selected blockgg=G
go 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/backwardw
to the next wordW
to the next space-separated wordb
/e
to the begin/end of the current word. (B / E for space separated only)gg
/G
jump to the begin/end of the file%
jump to the matching { .. } or ( .. ), etc...{
/}
jump to next paragraph'.
jump back to last edited linenG
jump to line nL
jump to the bottom of the screen ("low")H
jump to the top of the screen ("high")M
jump to the middle of the screen ("middle")C-o
jump backC-i
jump forwardzt
move this line to the top of the screen ("top")zb
move this line to the bottom of the screen ("bottom")zz
move this line to the middle of the screen ("ziddle?")
/search_pattern
find next match. Examples "/function" or "/\d{2}-\d{2}-\d{2}" to locate some date like "1981-06-13"?search_pattern
find match backwardn
repeat the next '/' or '?' commandN
same 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 = {}
I
insert at the begina
/A
append to next / append to endo
/O
open a new line after/before the currentv
/V
visual mode (to select text!)Shift+R
replace textC
change remaining part of linedd
delete current line (actually, moves it to Vim internal clipboard)D
delete until the end of the linedw
delete from current cursor until the end of the word under cursordiw
delete inner word (the entire word under the cursor)db
delete 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 ('', "", {}, (), [])dst
delete 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 charactersdit
delete inner tag contentcs
work likeds
but 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, whileyss
will 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)ys
applies surround around the region described by the movement command. Ex. With cursor under "word"ysiw
results inword
c
,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)\c
toggle line (or block in visual mode) commentingggdG
[d]eletes entire buffer - from beginning [gg] to end [G] of the document
cW
change till end of word3cW
change 3 wordsBcW
to begin of full word, change full wordciW
change inner wordci"
change inner between ".."ci(
change text between ( .. )4dd
delete 4 lines3x
delete 3 characters3s
substitute 3 characters
:set foldmethod=syntax
fold by syntax definitions:set foldmethod=indent
old by indentationzc
close the current foldzo
open the current foldzM
close all foldszr
open one level of foldszR
open all foldszj
move to the next foldzk
move to the previous foldzm
close one level of foldszn
disable foldingzN
re-enable folding
r
replace one character (e.g. rd replaces the current char with d)~
changes caseCtrl+A
/Ctrl+X
increments/decrements a number.
repeat last command (a simple macro)=
indent line (specify a range, or use visual mode)
bufdo
refresh all files in buffer from disk
w !sudo tee %
- Press
q[
key]
to start recording - Then hit
q
to stop recording - The macro can be played with
@[
key]