VI editor is a common and important editor in Linux. You can edit one or more files in full screen mode. If no file is specified during VI Execution, the VI command will automatically generate a blank
. If the specified file does not exist, create a new file based on the specified file name. If the modification to the file is not saved, the v I command does not change the content of the original file.
The following are some options and meanings used by the VI command:
-C sub-command: Before editing a specified file, run the specified sub-command.
-R filename: Restore the specified filename.
-R puts the specified file in the editor in read-only mode, so that no modifications to the file will be saved.
-Y number: set the size of the editing window to number.
The following are three modes of VI Editing:
. The mode in which the command mode enters VI. In this mode, you can enter various sub-commands to perform * operations, such as deleting, pasting, moving to the next word, and moving to different lines.
. Text input mode in this mode, you can modify the content of a row and add a new line. In command mode, enter the, I, or C key to enter the text input mode. Press the Escape key to return to the command mode.
. Command item mode in this mode, you can enter more parameters through sub-commands. For example, the W sub-Command requires entering a file name, and the "/" sub-Command requires entering a search item. The user uses the Escape key to return to the command mode.
The following is the self-Command executed in self-command mode and moved on the same line:
H. move the cursor to the left.
L move the cursor to the right.
J. move the cursor down one cell.
K moves the cursor up a grid.
W move the cursor to the front of the next small word.
W move the cursor to the front of the next large word.
B. move the cursor to the front of the previous small character.
B. move the cursor to the front of the previous character.
E move the cursor behind the next small word.
E. move the cursor behind the previous big word.
FC moves the cursor to the next C character in the same row.
FC moves the cursor to the first C character in the same row.
TC moves the cursor to the first grid of the next character C in the same row.
TC moves the cursor to the next cell of the first character C in the same row.
Number | move the cursor to the number column.
The following is a sub-command to change the screen display in command mode:
Z-use the current row as the last line of the screen and display the screen again.
Z. Use the current row as the middle line of the screen and display the screen again.
CTRL + l re-display the current content of the screen.
/Pattern/Z-find the next position of pattern and set the row as the last line of the screen.
The following is a sub-command to move between lines in command mode:
+ Or enter to move the cursor to the first non-blank character in the next line.
-Move the cursor to the first non-blank character in the previous line.
0 move the cursor to the first character of the current row.
$ Move the cursor to the last character of the current row.
H move the cursor to the top row of the screen.
L move the cursor to the bottom of the screen.
M moves the cursor to the center of the screen.
The following sub-commands are used to search for strings in command mode:
/Pattern: Search for the specified pattern. If the end of the file is reached, start from the beginning.
? Pattern looks forward to the specified pattern. If a file header is encountered, it starts from the end.
N re-executes the last defined search in the specified direction.
N re-executes the last defined search in the opposite direction of the last specified direction.
/Pattern/+ number: place the cursor on the number line behind the row containing pattern.
/Pattern/-number: place the cursor on the number line before the row containing pattern.
% Moved to the matched "()" or.
The following sub-commands are used to display the page in command mode:
CTRL + F roll back one page.
CTRL + D roll back half page.
CTRL + B roll forward one page.
CTRL + u roll forward half page.
CTRL + e scroll down a line.
CTRL + y roll up a row.
The following is a subcommand used to input text in text input mode (you can return to the command mode by escape at any time ):
A starts to input text after the cursor.
A. Enter text at the end of the row.
I start to input text before the cursor.
I. Enter text before the first non-blank character in the row.
O insert an empty row behind the row where the cursor is located.
O insert an empty row before the row where the cursor is located.
The following sub-commands are used to change the text in command mode (you can press the Escape key to return to command mode at any time ):
Cc or S.
C. The part after the cursor position of a row.
CW changes the word where the cursor is located.
Dd deletes the current row.
D. Delete the content behind the cursor in the row.
DW deletes the word where the cursor is located.
J. Add the content of the next row to the end of the row.
RC replaces the character of the optical character with C.
R covers the content of the bank.
U resumes the last modification.
X deletes the character of the cursor.
~ Change the case sensitivity of the output character of the cursor.
. Repeat the previous * operation.
<Move the current row to the left.
> Move the current row to the right.
The following command is used to copy text in an object:
P retrieves the content of the buffer to the bottom line of the row where the cursor is located.
P retrieves the buffer content from the top row of the row where the cursor is located.
"BD deletes the text to the famous Buffer Zone B.
"BP posts the content in the famous Buffer Zone B.
YY puts the current row into the buffer.
Y puts the current row into the buffer.
YW puts the word with the cursor in the buffer zone.
: G/<pattern>/d, delete all rows that match <pattern>
The following sub-commands are used to save files:
: W: Write back the modified file.
: W filename: If filename does not exist, save the modified file as filename. If filename exists, an error is returned.
! W filename if the filename file exists, save the modified file as filename.
The subcommands used to switch between multiple files edited by VI are listed below:
: N start to edit the next file in the VI activated file list.
: N filenames: Specifies the list of new files to be edited.
The subcommands used to switch between the current file and another file are listed below:
: E filename: Use filename to activate VI (add another file filename to VI ).
E! Reload the current file. If there are changes to the current file, the previous changes will be discarded.
: E + filename use filename to activate VI and edit it from the end of the file.
: E + number filename use filename to activate VI and edit it in row number.
: E # start editing another file.
The following sub-commands are used to add other file codes to this file:
: R filename reads the filename file and adds its content to the current file.
: R! Command to execute the command file and add its output to the current file.
The following are other sub-commands in VI:
CTRL + G to obtain information about the file being edited.
: Sh start SH, return available exit or Ctrl + D from Sh.
:! Command to execute command.
!! Re-execute the last :! Command subcommand.
: Q exits VI. If the user modifies the edited file, the system does not allow the user to exit using the Q command.
: Q! Exit VI, regardless of whether the file is changed.
ZZ or: WQ Save the changes to the file and exit VI.
You can define special VI commands in a special file. exrc. When using these commands in VI, you must add a colon Before the command.
Note: The vi command does not lock the edited object. Therefore, multiple users may edit an object at the same time, and the last saved file version will be retained.