- ← → ↑ ↓
b
/B
: go to the start of the previous word/Wordw
/W
: go to the start of the following word/Word0
/g0
: go to the first column of the line/current window$
/g$
: go to the end of the line/current window^
: go to the first non-blank char of linegg
/G
: jump to the begin/end of the file<Number>G
/<Number>gg
: jump to nth line
h
/j
/k
/l
: ←/↓/↑/→e
/E
: go to the end of this word/WordgE
: go to the end of the previous word%
: 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,
: repeat the last f/t/F/T motion backwardH
: 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)''
: jump back(to the cursor position before jumping)- combine
<num><motion>
: Repeat motion num of times.
'<mark>
: jump to mark(See below)g_
: go to the last non-blank char of line
normal mode options
i
: insert mode under cursor<ECS>
/Ctrl+[
: back to normal mode- *
yy
/Y
: yank(copy) a line with/without last \r - *
dd
/D
: delete(cut) a line with/without last \r - *
cc
/C
: change(cut and enter insert mode) a line p
/P
: paste yanked or cut things under/before cursor
x
/X
: cut the char under/after cursors
/S
: cut the char under/after cursor and enter insert moder
: replace the char under cursorR
: enter replace modea
: append(insert) after cursorI
/A
: insert/append(**insert before/after) the lineo
/O
: open a new line below/above and enter insert mode- *
<<
: add a indent to current line - *
>>
: remove a indent from current line v
: enter visual(select) mode to select part of code, then usey
to yank(copy) the selected code
J
: join lines together- *
gUU
: make the line uppercase - *
guu
: make the line lowercase - Dark Magic:
- combine
<num><change>
: Repeat change num of times. - combine
<change><adjective><position>
: For reduplicated change marked with *(i.g.y
,>
,gU
, 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
press <enter> after typing
:w
: write(save) the file:q
: quit:x
: save and quit(=:wq
)
:w <fileName>
: write(save) the file to fileNameZZ
: save and quitZQ
: quit without saving
.
: repeat the last modification to the file/<pattern>
: search pattern//
: 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
:!<command>
: execute command in shell:!!
: repeat last!<command>
/<pattern>/<offset>
: search pattern and place cursor on offset:&<flag>
: repeat lasts/<pattern A>/<pattern B>/
with flag:~<flag>
: use last/<pattern>
as pattern A and last:s
pattern B with flag:g/<pattern>/<command>/
: execute command at lines that match pattern:sh
: go to shell. come back by$exit
- notes:
<offset>
:- +-n: move n lines
- b+-n: n char from begin of word
- e+-n: n char from end of word
<flag>
:g
: apply to all matches&
: use previous flagc
: comfirm neededi
: ignore caseI
: don't ignore case
- replace string(
<pattern B>
):&
:<pattern A>
~
: previos<pattern B>
\<num>
: pattern within ()
:saveas <path/to/file>
: save to<path/to/file>
<start position><command><end position>
insert mode options
Ctrl+n
/Ctrl+p
: select next/previous option in autocomplete or trigger default autocomplete behavior
Ctrl+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 filesCtrl+t
: add a indent to current lineCtrl+d
: remove a indent of current lineCtrl+w
: delete word before cursorCtrl+u
: delete line before cursor
Ctrl+g j
: equivalent to<ESC>ji
Ctrl+g k
: equivalent to<ESC>ki
Ctrl+o <command(**normal mode**)>
: equivalent to<ESC><command>i
Ctrl-r <register>
: insert from <register>Ctrl-a
: insert last text(equivalent to^r.
)Ctrl-@
: insert last text and leave insert mode(equivalent to^a<esc>
)
Advanced or above
zz
/z.
: scroll the screen so that the cursor is in the middle of the screenCtrl+d
: scroll half the screen downCtrl+u
: scroll half the screen upzt
/zb
: scroll the screen so that the cursor is in the top/bottom of the screen
'"
: jump to the cursor position last exitingm<letter>
: mark the line with letter
Ctrl+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)
- macro
qa<commands>q
: record actions in the register a@a
: replay the saved actions once (same as@@
)<number>@@
: replay the saved actions N times
@:
: replay last command@/
: replay last search- default
"0
: last yank"<1~9>
: delete history"%
:fileName"/
: lastest search,":
: latest command,".
: latest insert"*
: system clipboard
- others:
"ayy
(yank(copy) the current line and store it to register a)"ap
(paste register a)
:new
/:vnew
: new empty window:sp <fileName>
/:vsp <fileName>
: new window for fileNameCtrl-w w
: switch to the other bufferCtrl-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
zf
: create a foldzo
: fold openzc
: fold closezd
: fold deletezR
: open allzM
: close all
- step1: press
Ctrl+v
- step2: select multiple lines as if in visual mode
- step3: edit ONLY the first line
- step4: press
<ecs>
- step5: be amazed
- vim :help motion, insert, scroll, change, fold, reg, mark, ctrl-v, windows, i_ctrl-n, etc.
- vim tips
- Learn Vim Progressively
- 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
- 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
- ref
- CONFIG
- push
git push -u <remote name> <branch name>
: upload and track remote branch
- semantic commits
- chore : Changes to the build process or auxiliary tools and libraries such as documentation generation
- docs : Documentation only changes
- feat : A new feature (CHANGE LOG)
- fix : A bug fix (CHANGE LOG)
- refactor : A code change that neither fixes a bug or adds a feature
- style : Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- test : Adding missing testing
- ref