First, VI working mode
*******************************************************************
VI filename---> Command mode------>:WQ exit
Input i a o-----> Insert mode----->esc key------> Command mode
Command mode:---> Edit mode------> Command to end Run with enter
Second, basic use
*******************************************************************
Insert command
A append text after the cursor
A additional text at the end of our line
I insert text before the cursor
I start inserting text at the bank
o Insert a new line under the cursor
O insert a new line on the cursor
Position command
H, left ARROW to move one character
J, the direction of the next key move down one line
K, move the key up one line above the direction
L, right-click one character to the right
$ move to end of line
0 move to the beginning of the line
H Move to upper screen
M move to the center of the screen
L move to the bottom of the screen
: Set Nu Sets line number
: Set Nonu Cancel line number
GG to First line
G to last line
NG to Nth row
: N to Nth row
Delete command
X Delete the character at cursor location
NX removes the n characters after the cursor is located
DD Delete Row of cursor, NDD delete n rows
DG deletes the contents of the line to the end of the cursor
D Delete from the cursor to the end of the line
: n1,n2d deletes a specified range of rows
Copy and Cut commands
yy, Y Copy as Forward
Nyy, NY Copy the current row following n rows
DD Cut when moving forward
NDD cuts the current row following n rows
P, p pasted under the current cursor row or line
Replace and Cancel commands
R replaces the character at which the cursor is located
R replaces the character at the beginning of the cursor and presses ESC to end
U Cancel the previous action
Search and Replace commands
/string forward search ignores case when searching for specified string: Set IC
n searches for the next occurrence of the specified string, n the previous position
:%s/old/new/g full text Replace specified string
: N1,n2s/old/new/g replaces specified string within a certain range
Save exit
: Wq shortcut key shift zz ZZ = =: Wq
: wq! Force Save exit
: W Save: Q exit
: W/test/service.bak saved as a backup
Third, application examples
*******************************************************************
1) Import the contents of other files
: R/test/service.bak
2) Execute the command directly in VI
! Command!ls-l/test
3) Import the results of a command execution directly into the edit file
: R!date
4) vi define shortcut keys
: Map ^p i#<esc> ^p Ctrl + V ctrl+p Plus # comment
: Map ^e [email protected]
: Map ^b 0x minus # comments
5) Continuous Line annotation
: n1,n2s/^/#/g (^ represents the beginning of the line) (s specifies row,%s full text)
: n1,n2s/^#//g
: n1,n2s/^/\/\//g
6) Replace
: AB mymail [email protected]
: Unab mymail Cancel
7) Edit VI configuration file to save configuration information
~ Home Directory
Root/root Users/home Zhangsan/home/zhangsan
~/.VIMRC configuration file
Vi/vim use