BEHOLD the power of Vim
%
: go to the corresponding (, {, [*
/#
: go to next/previous occurrence of the word under cursorf<letter>
: find(go to next occurrence of the) lettert<letter>
: find till(go to just before the occurrence of the) letterF<letter>
: go to previous occurrence of the letterT<letter>
: go to just before the occurrence of the letter before;
/,
: repeat the last f/t/F/T motion forward/backward- combine
<num><motion>
: Repeat motion num of times.
H
: jump to High position(place the cursor on the top of screen)M
: jump to Middle position(place the cursor at the middle of screen)L
: jump to Low position(place the cursor at the bottom of screen)'<mark>
: jump to markCtrl+o
: undo jumppingsCtrl+i
: redo jumppingsCtrl+]
: jump to definition(REQUIRE A TAG FILE)Ctrl+t
: reverse previous jump-to-definition behavior(REQUIRE A TAG FILE)g]
: similar toCtrl+]
but choose from list of options:tn
: jump to the next tag in the list:tp
: jump to the previous tag in the list
J
: join lines togethergUU
: make the line uppercaseguu
: make the line lowercaseg~~
: switch case of the line~
: switch case of the letter on cursor- Combine:
- combine
<num><change>
: Repeat change num of times. - combine
<change><adjective><position>
: For reduplicated change marked with *(i.g.y
,>
,gU
,g~
etc.), apply change from cursor to position.- <adjective>(optional):
i
: in,a
: all, <num>: repeat - <position>: motion or <num><motion> or {, [, (, ), ], }
- <adjective>(optional):
- examples:
y$
: yank from the cursor to the end of linediw
: delete in word(the word touched by cursor)ca)
: change(delete and enter insert mode) things within ( and )(included)2d3w
: delete 3 word twice
- combine
Ctrl+n
/Ctrl+p
: select next/previous option in autocomplete or trigger default autocomplete behaviorCtrl+w
: delete word before cursorCtrl+t
: add a indent to current lineCtrl+d
: remove a indent of current lineCtrl+u
: delete line before cursorCtrl+x Ctrl+f
: autocomplete for file pathCtrl+x Ctrl+]
: autocomplete for tags(REQUIRE A TAG FILE)Ctrl+x Ctrl+i
: autocomplete from this and included files
//
: repeat last/<pattern>
:Ctrl+n
/:Ctrl+p
: to select next/previous command/Ctrl+n
//Ctrl+p
: to select next/previous search:%s/<pattern A>/<pattern B>/g
: substitude all the pattern A in file by pattern B:marks
: list marks:f
: show file path (=Ctrl+g
)
m<letter>
: mark the line with letter'<mark>
: jump to mark- useful default marks:
'"
: jump to the cursor position last exiting''
: jump back(to the cursor position before jumping)
- macro
q<letter><commands>q
: record actions in the letter register@<register>
: replay the saved actions once (same as@@
)<number>@@
: replay the saved actions N times
- default registers (Useful)
"0
: last yank"<1~9>
: change history"%
:fileName"/
: lastest search":
: latest command".
: latest insert"*
: system clipboard
- techniques:
"ayy
(yank(copy) the current line and store it to register a)"ap
(paste contents in register a)@:
: replay last command@/
: replay last search
.
: repeat the last modification to the file
zz
/z.
/zt
/zb
: scroll the screen so that the cursor is in the middle/middle/top/bottom of the screenCtrl+u
/Ctrl+d
: scroll up/down (half of screen)
zo
/zO
: fold openzc
/zC
: fold closezd
: fold deletezR
: open all recusivelyzM
: close minimize allzf
: create a fold
:new
/:vnew
: new empty window:qa
: close all windows:sp <fileName>
/:vsp <fileName>
: new window for fileNameCtrl+w v
: split verticalCtrl+w w
: switch to the other windowCtrl+w k
: move the current window to topCtrl+w h
: move the current window to leftCtrl+w j
: move the current window to bottomCtrl+w l
: move the current window to rightCtrl+w |
: maximize window in splitted verticallyCtrl+w _
: maximize window in splitted horizontallyCtrl+w =
: distribute space equally for opened windows
:e <fileName>
: to add <fileName> into buffer:ls
: see all the buffers:bu<num>
/<num> Ctrl-^
: jump to <num> of buffer:bu#
/# Ctrl-^
: jump to previous buffer:wa
: save all the buffers
- launch
- bash
vimdiff [file_left] [file_right]
vim -d [file_left] [file_right]
- vim visual mode
:vertical diffsplit [file_left]
- compare existing windows
:windo diffthis
- bash
- cursor
]c
: move to the next difference block[c
: move to the last difference block
- merge
do
: (diff get) get difference from compared filedp
: (diff put) put difference to compared file
- misc.
- vim visual mode
:diffupdate
: update difference between files:set diffopt=context:<number>
: change the number of lines of context in each difference block
- vim visual mode
- ref