This is the 11th day of my participation in the More text Challenge. For more details, see more text Challenge
Use the Vi editor
The vi command is the most commonly used text editor on the Linux character interface.
The VI editor is the standard editor for all Linux and is used to edit any ASC ⅱ text, especially useful for editing source programs. Iv editor is very powerful, you can create, find, replace, delete, copy and paste text and other operations.
After you enter vi and the file name at the Shell prompt of the Linux operating system, the VI editing page is displayed. If the file does not exist in the system, it equals to create a new file, if the system exists in the file, it means to edit the file.
1. Access the Vi editor
Terminal Enter the file to be modified using vi
For example, vi hello.txtCopy the code
Syntax format: vi [parameter]
Common parameters: -r Read-only mode + Start from the end of the file -m Cannot be modified (written) -b Binary mode -m Cannot be modified in textCopy the code
2. Three modes of the VI editor
The VI editor has three modes:
1) Select mode 2) Edit mode 3) Bottom line modeCopy the code
When entering the VI editor, the default is select mode (nothing can be done in this mode).
Enter a lowercase I to enter edit mode. In edit mode, press the left, right, up, down key to move the cursor to modify the file content.
Use the Esc key to enter the bottom line mode (which we use to type commands and keyboard).
Common commands: 1) :q exit 2) :q! 3) :w Save 4) :wq save and exit 5) :wq! 6)/fields For example: /hello finds the line in the file containing the entire field of hello, n goes to the next hello, 7) :s/ original field/New field replace the original field on the line where the cursor is located with the new field 8) :%s/ original field/New Field replace all the original fields with the new field 9) :set nu open line number 10) :set nonu close line number 11) :r filename reads the contents of a file Write to the current editor 12) :w newfilename writes the contents of the editor to a newfile 13) u Undo the previous step 14) :e Return the current file to the last save 15) :e file Switch edit fileCopy the code
Common keyboard operations: 1) Delete a line of cursor positioning to the line dd number +dd means starting from the positioned line and delete the following n line 2) Copy a line of positioning to the line YY number + YY means starting from the positioned line, Copy the following n lines 3) p paste 4) the number gg to go directly to the beginning of A line 5) G to go directly to the end of A line 6) I (capital I) to go directly to the beginning of A line and enter edit mode 7) A to go directly to the end of A line and enter edit modeCopy the code