Vim is an upgraded version of VI
The most obvious difference is that vim displays the contents of the file into a highlighted color.
There are many conditions for vim to display colors, and the same file will show different colors in various directories.
Install Vim
[email protected] ~]# Yum install-y vim-enhanced
Vim is divided into general mode, edit mode, command mode
Direct Vim or VI into a file, we are in the general mode, is not modifiable, only up and down left and right to view
Vim quickly moves to the last line of a text file by pressing the G key in normal mode, and two g quickly moves to the top line of a text file
Quick positioning to 30 rows
30G, where you want to position the cursor, enter the number of lines plus g
I key to start inserting is to enter edit mode
Vim + 3 File
Open file cursor starts from line three
First input in Vim: then enter set Nu to display the preceding line number
General mode:
DD Delete/Cut the line where the cursor is located
x or x x indicates that a character is deleted backwards, and x indicates that a character is preceded by a byte number to be deleted.
N+x Remove n characters backwards
NDD (abbreviation for number N) Delete/cut n rows after the line where the cursor is located
YY the copy cursor is in the row
P Paste the copied contents down from the line where the cursor is located
P paste the copied content up from the line where the cursor is located
U Restore previous action
V Press V to move the cursor will be selected to set the character, and then can be copied, paste and other operations;
Ctrl+f PAGE Down
Ctrl+b PAGE Up
Edit mode:
I insert in the current word match either
I Insert at the beginning of the line where the cursor is located
A in the current word specifier insert
A at the end of the line where the cursor is inserted
o Insert a new row on the next line of the current row
O Insert a new row on the previous line in the current row
Command mode:
/+ Find content, look after the cursor, press N to go back to search
? + Find content, look in front of cursor, press N to continue search
: W Keep text
: Q Quit Vim
: Wq Save and exit
: q! Force exit
: w! Force save, under root user, even if the text is read-only can be saved
: Set NU Displays line number
: Set Nonu does not display line numbers
: 1, $s/etc/abc/g replace all the ETC characters with ABC from the first line to the last line
$ can also be used with other numbers, but in the range of lines.
Example:
Delete all contents of 第37-42 line (37G 6DD)
Copy the contents of line 48th and paste it below line 52nd (48G yy 52G p) p lowercase
Copy the contents of the 第37-42 line and paste it onto line 44th (37G 6yy 44G p) p uppercase
Move the contents of the 第37-42 line below line 19th (37G 6DD 19G p)
To replace the specified character with the specified character.
Example: When editing a document, I would like to enter a continuous string such as "abcdefghijklmnopqrstuvwxyz", when I want to enter only one or a string of specified characters can be replaced with just the character, such as I specify the input "aming" system will automatically put " Aming "Replace with" ABCDEFGHIJKLMNOPQRSTUVWXYZ "
Enter ": AB aming abcdefghijklmnopqrstuvwxyz" in the general mode and then enter the edit mode, and when you enter "aming" you will find that the "ABCDEFGHIJKLMNOPQRSTUVWXYZ" is automatically replaced.
Vim Introduction using