Directly go to the topic:
Basically, VI is divided into three modes: general mode, edit mode, and command mode. The functions of these three modes are as follows:
Normal Mode: open a file using vi and directly enter the normal mode. In this mode, you can move the cursor by using the upper/lower keys. You can delete characters or the entire line, you can also copy and paste your file data.
Edit mode: In normal mode, you can delete, copy, paste, and other operations, but you cannot edit the file content. You need to press I, I, O, O, a,, enter the editing mode after any letter, such as R and R, and Press ESC to exit the editing mode.
Command mode: In general mode, enter :,/,? The character enters the command mode. In this mode, you can provide operations for searching data, while reading, saving, replacing a large number of characters, leaving VI, the row number is displayed in this mode.
Common Operations of VI:
The following buttons can be used to switch the general mode to the command mode:
: W writes the edited data to the hard disk
Write Data to Hard Disk
: Q exit vi
: Q! If you have changed the file and it is not like storage, use it! To force exit without saving the file
: Set nu display row number
: Set Nonu cancel row number
Common buttons in Normal Mode
Dd deletes the row where the cursor is located.
YY copy the row where the cursor is located
U restore operation
P paste the copied data in the next row of the cursor.