"Vim" is a very powerful and widely used editing method in Linux. Here are some basic uses of "Vim". Take "/etc/passwd" as an example.
1. Vim Command mode
Enter ": Set Nu" To add the line number as shown in. ": Set Nonu" To cancel the line number. ": Set Mouse=a" To add a mouse selection. ": Set Cursorline" To display line lines under the cursor.
The above settings are only in the current "vim" in effect, if required to be permanent, then enter the command "VIM/ETC/VIMRC", this file is a vim configuration file, the file is added to the above parameters, the subsequent "vim" will take effect, such as adding "Set Nu" in the configuration file, later use "Vim" will automatically display the line number.
2, the VIM command mode keyword search
"Vim" is also a keyword search function in command mode for ease of use. "/keyword" can find the file quickly, find the "bin" keyword in the file. n matches the keyword down, n matches the keyword up.
3. Character management in vim command mode
The character management of VIM command mode mainly provides copy, delete and cut function of text.
The copy of the character uses "Y". "YL" means copying a letter, "ynl" means copying n letters, "yw" means copying a word, "ynw" means copying n words, "yy" means copying a row, "yny" means copying n rows, after the copy is complete, press "P" at the destination where you want to copy to complete the copy, to use "yy" Copy a whole line. Copy line 4th to line 5th.
The deletion of characters uses "D". "DL" means to delete a letter, "DNL" means to delete n letters, "DW" means to delete a > Word, "dnw" means delete n words, "dd" means to delete a row, "DND" means to delete n rows, to use "dd" to delete a whole row. The 1th row was deleted.
The cut of the character uses "C". "CL" means cut one letter, "CNL" means cut n letters, "CW" means cut a > Word, "CNW" means cut n words, "cc" means cut a line, "CNC" means cut n rows, after cut will go into insert mode, when performing paste action, you must press "ESC" Exit insert mode, and then press p at the target location to cut an entire line using CC.
4. Vim Visualization mode
Press "CTRL + V" in command mode to enter the visual mode, where you can select the characters in the visual mode. As shown, select the column where you want to add the character, press "I" into insert mode, write the character "XXXX" to be added, and then press ESC to add "XXXX" before the entire column selected.
5. Bulk modification of characters
In one text, if you need to bulk modify characters, you need to enter the command ":%s/original character/replace character/g" If there is no "G", only the first existing character appearing in each row will be replaced, as shown in the above command to change "bin" to "ddddddddddd".
If you only need to replace the first few lines, you need to enter ": 1,ns/character/replace character/g", for example, replace 1 to 5 rows of "Bin" with "ddddddddddddddd".
6. Vim's split screen function
When the "Vim" editing text, sometimes use the split screen function, the "ctrl+w" together, and then press "S" will appear up and down the split screen.
Press "V" will appear left and right split screen.
Press "C" to close the screen where the cursor is located, press up or down to move the cursor to the specified screen.
In the case of a "vim" open, enter ": SP file2" To edit both the current file and the "File2".
7. VIM Cursor Movement
In command mode, enter ": Number" can be moved to the specified line, press "G" can move to the first line of the file, press "GG" can be moved to the last line of the file.
In the Insert mode, press "I" can be inserted at the cursor position, press "I" can be inserted at the beginning of the line of the cursor, press "a" can be at the cursor where the character of the next position, press "a" can be at the end of the line of the cursor and so on.
8. Vim's exit
After editing the file or after viewing the file, you can enter ": Q" To exit, the character operation, but to discard all operations to enter ": q!", enter ": Wq" can save exit, enter ": wq!" Forcibly saves the exit and takes effect for the superuser and the file owner.
9. Other
When editing a file, you can also use the command "Gedit file" to open the Gedit graphical interface to write text.
These are some of the basic editing features of Vim, as well as other features that need to be understood and familiar with later learning.
Linux Beginner-Edit File tool vim