Mode
- insert
- normal
- visual
- command
Insert mode
- i
- insert before the cursor
- I
- insert before the start of line
- a
- append after the cursor
- A
- append at the end of line
Normal mode
<ESC>
Visual mode
- v
- select a char
- V
- select a line
- Ctrl + v
- visual block mode
Command mode
:
+ <command>
1 | :wq |
Cursor movement
Char
- h (left)
- j (down)
- k (up)
- l (right)
- Combile with number to move,
2k
to jump 2 lines up - Relative line numbers
:set rnu
Word
- w or W
- jump forwards to the start of a word
- e or E
- jump forwards to the end of a word
- b or B
- jump backwards to the start of a word
- Capital case can contain
punctuation
Single line
- $ - end of line
- ^ - start of the line after the indentation
- 0 - move to the column 0
Text Object motion
- {}
- paragraphs forward/backward
- ()
- sentences forward/backward
- []
- backward/forward sections
Pair
- %
- go to the match bracket
Screen
- H
- move to top of screen
- M
- move to middle of screen
- L
- move to bottom of screen
File
- gg
- Start
- G
- end of file
- :
<absolute-line-numbers>
- move to the absolute line
Scroll
- zt
- scroll current line to top
- zb
- scroll current line to bottom
- zz
- scroll current line to middle
Search
Search char in single line
- f/F
- find char, forward/backward
abcABCabc
,fC
to find middle C
- t/T
- Go to previous char before the char, forward/backward
foo.bar<>
, move to r byt<
- ;
- Repeat
t/T/f/F
- Repeat
- ,
- Reverse
t/T/f/F
- Reverse
Search in file
- /
- Search forward
- ?
- Search backward
- n and N
- next and previous
- *, #
- search next/previous current word
- The behavior is identical to /
word
Edit
- Undo/Redo
- u / Ctrl+r
Insert
- insert line before/after the current line
- o, O
- join two line (keep mode)
- J
Copy
- y + motion
- combine with any motion, e.g.
yt;
oryw
- combine with any motion, e.g.
- yy = Y
- yank (copy) the current line
Paste from clipboard registry
p
- paste after
P
- paste before
Cut and switch to insert mode
- c + motion
- Cut
- C
- Cut to end of line
- s
- Substitute the char under the cursor
- S
- Substitube the line
- r
- replace a char
- R
- Enter the insert-replace mode
Cut and keep in normal mode
- d
d3j
or3dd
- D
- Delete to end of the line
- dd
- Delete the entire line
- x and X
- delete and backspace
inside / around
1 | # edit neariest word inside symbol, e.g. } |
Repeat action
- repeat action
- .
Macro
q
+a~z
- record macro to
a~z
- record macro to
normal mode
+q
to quit recording@
+a~z
to excute macro
Bookmark
m
+a~z
- bookmark current location to
a~z
- bookmark current location to
'
+a~z
- go to a~z bookmark
''
- go to the last position
Registers
"
+a~z
0~9
"+*/:%-
:reg
see all registers"
the default(unnamed) register0
the default register fory
(yank)+
,*
the system clipboard/
the latest search keyword:
the latest used command%
the current file path#
the last edited file
“adw : delete the word and save to register
a
===
Registers - Advance
"0p
- paste from last yank- Use the register in the
Search
andCommand mode
ctrl
+r
+<register>
*:%s/<ctrl+r>//abc/gc
to replace the lastest search keyword(*) toabc
with confirmation dialog
Change multi line
Ctrl + v
to enterVisual block mode
- Move cursor to select lines that need to be edited
Shift + i
#
- Esc
More
1 | # increase the first right number in the line |
More…and more
- ctrl+o
- previous jump position
- ctrl+i
- next jump position
- g;
- previous Change position
- g,
- next Change position
vim X IDE
Setup
Ideavim
- click the
V
icon on the right bottom corner - open
~/.ideavimrc
- edit and save
- click the
Reference
Get the difference before saving in vim
1 | :w !diff % - |
w
without filename will output to stdin!
will excute bash in vim%
is current file in vimdiff
with-
will read content from stdin