vim is stand for Vi IMitation.
It has three modes for specialized function.
edit mode for text editing.
command mode for using command to quickly apply function, like copy, paste
last line mode for file option, like save, quit
########################################
1. change the mode
from edit modo to command mode, Esc
from command mode to edit mode,i a o
from command mode to lastline mode, :
from lastline mode to command mode,Esc Esc
#######
2 open the vim
vim vim.vim , open to first line
vim + vim.vim , open to lsat line
vim +12 vim.vim, open to specific line
vim +/pattern vim , open to first matched line
#######
3 cloes the vim
1) in the last line mode
:q quit
:w save
:wq save and quit
:q! don`t save and quit
:w! force save
:x save and quit
2) in the command mode
shift + zz
#######
4 cursor control - command mode
1) in a character
h ,a letter to the left
l , a letter to the right
j , a line down
k , a line up
12h ,12 letters to the left
2) in a word
w , to the beginning of the next word
e , to the ending of the current or next word
b , to the beginnning of the current or next word
12 w , to the beginning of the 12th word
3)inline jump
0 ,absoute beginning of line
^ ,the first non-blank character of line
$ , absolute ending of line
4) between line
12G , 12th line
G , the last line
at the last line mode,12 + enter , means jump to the 12th line.
#######
5 secreen flipping - command mode
Ctrl + f , flip to the next screen
Ctrl + b , flip to the before screen
Ctrl + d , flip to the next half screen
Ctrl + u , flip to the before half screen
#######
6 delete - command mode
x , delete the character in the cursor
12x , delete the character in the cursor and the following 11 characters
dw , delete the word with the cursor
12dw , delete 12 words herafter
de , delete the word after the cursor
12de ,
db ,delete the word before the cursor
12db , delete 12 words herbefore
dd , delete the line with the cursor
12dd , delete the line with the cursor and the following 11 lines
d$ ,
d0 ,
d12 ,
in the last line mode,STARTaddress,ENDaddress , delete the line from STARTaddress to ENDaddress
. the current line
$ the last line
$-2 the last 3rd line
+12 the 12th line from current cursor
#######
7 paste - command mode
p , paste the deleted or copied text after the cursor
P , paste the deleted or copied text before the cursor
#######
8 yank - command mode
usage same as delete
yy
3y
last lind mode , y3,13
#######
9 change - command mode
delete the text, then insert text by convertting to edit mode
usage as delete
cc ,
3c ,
#######
10 replace - command mode
r , replace the current character in the cursor with a character
usage same as change
R , convert into raplace mode , everything inputted will cover the existed text
#######
11 undo
u , undo the last operation
uuuu , undo the last 4 operetions(maximun 50 times)
4u , same as uuuu
Ctrl + r , undo the last undo
#######
12
. , repeat the last operation
#######
13 visulization mode
v , choose by character
V , choose by line
combine with other operation
#######
14 search - command mode
/pattern
?pattern
n
N
#######
15 search then replace - last line mode
s
usage same as sed
STARTadd,ENDadds@pattern@string@gi
#######
16 edit multiple files - command mode
vim FILE1 FILE2 FILE3 , open multiple files
:next , change to next file
:prev , change to previous file
:last , change to last file
:first , change to first file
:qa , quit all files
#######
17 show a file screen-separately - command mode
Ctrl + w , then s , split horizontally
Ctrl + w , then v , split vertically
Ctrl + w , then ARROWs , change cursor between files
#######
18 edit multiple files
vim -o FILE1 FIEL2 , show files in different windows horizontally
vim -O FILE1 FILE2 , show files in different windows vertically
#######
19 other save - last line mode
:w
:STARTadd,ENDaddw /path/to/somewhere , save the text between STARTadd and ENDadd to other file
#######
20 fill it with other file - command mode
:r
:r /path/to/somefile
#######
21 interact with shell - last line mode
:! + shell command
#######
22 others
1) show line number - command mode
:set number
:set nu
:set nonu
2) ignore or dictinct capital and small letter - command mode
:set ignorecase
:set ic
:set noignorecase
:set noic
3) set automatic indentation - command mode
:set autoindent
:set ai
:set noai
4)highlight show of searched text - command mode
:set hlsearch
:set nohlsearch
5) syntax coloring - command node
:syntax on
:syntax off
#######
23 configuration files
/etc/vimrc , effective for all user
./vimrc , effective for current user
change configuration files to apply setting on all users or current user