5.1vim Introduction
Vim is an upgraded version of VI with a color display that installs the package first
Yum install-y vim-enhanced
Vim is divided into three modes: General mode, edit mode, and command mode.
5.2vim color display and move cursor
The same file information is displayed differently in different directories.
The same content, different file names, the display color will also vary.
Vim's configuration file/ETC/VIMRC.
Move the cursor in 5.3vim general mode
In the general mode:
h or LEFT ARROW key cursor moves one character to the left
L or RIGHT ARROW key or SPACEBAR cursor move one character to the right
Ctrl+f or PageUp key screen move forward one page
Ctrl+b or PageDown key screen to move backward one page
The number 0 or shift+6 moves to the beginning of the bank
Shift+4 move to the end of bank line
GG moves to the first line
G move to Tail line
NG (n is any number) moves to nth row
number + corresponding key command, move the corresponding number * The corresponding key represents the amount of movement. If 5h means move 5 characters to the left.
5.4 Copy cut paste in general mode
X,x x to delete a character, x to delete one character forward
NX removes n characters backwards
DD Delete/Cut the line where the cursor is located
NDD Delete/cut n rows after the line where the cursor is located
YY the copy cursor is in the row
P start with the cursor line and paste the copied or pasted content down.
P from the cursor line, paste the copied or pasted content up.
Nyy starts from the cursor line and copies n rows down
U Restore previous action
CTRL+R Reverse Recovery
V Press V to move the cursor will select the specified character for copying and pasting
5.5 Entering edit mode
Press Iiaaoorr any character to enter edit mode.
I current word match either insert
I Insert at the beginning of the line where the cursor is
A current word specifier insert
A line end of the line where the cursor is inserted
o The next line of the current row inserts a new row
O Insert a new row on the previous line of the current row
5.6vim Command mode
/word After the cursor looks for a string word, press N to go back to search
? Word looks for a string before the cursor word, press N to continue searching
: n1,n2s/word1/word2/g find word1 between n1-n2 rows and replace with Word2, and no G replaces only the first word1 of each row
: 1, $s/word1/word2/g replace all word1 in the document with Word2, and no G replaces only the first word1br/> of each row if word1 or word2 exists/, the system will not recognize the command. Need to be/de-justified, that is, in/before plus \, that is,/. or use the # or @ symbol as the delimiter for the command, such as:
: 1,[email protected]@[email protected]
: w Save text
: Q quit vim
: w! Force save, under root user, even if the text is read-only can be saved
: q! Force exit, all changes are not valid
: Wq Save and exit (changes mtime even if the content has not changed)
: x saves exit, similar to: Wq, but does not change the mtime if nothing is changed.
: wq! Force Save and exit
: Set nu Displays line number
: Set Nonu does not display line numbers
: Nohl not highlighted
5.7vim Practice
Do not memorize the operation of the command, more practice practice.
"Linux Learning Notes" Chapter 5th VIM Tools