Detailed explanation of vi\vim command in Linux

Adding and modifying configuration files generally use the default VI editor, and programmers who edit code for a long time will use a more powerful editor.
Briefly introduce how to use the vi editor:
1. vi can be divided into three states, namely command mode, insert mode
and last line mode. The functions of each mode are distinguished. As follows:
1. Command mode command mode)
Control the movement of the screen cursor, the deletion of characters, words or lines, move and copy a certain section and enter the Insert mode, or to the last line mode.
2. Insert mode (Insert mode) is
only in Insert mode, you can do text input, press "ESC" key to return to command line mode.
3. The last line mode (last line mode)
saves the file or exits vi. You can also set the editing environment, such as searching for character strings, listing line numbers, and so on.
However, in general use, vi is simplified into two modes, that is, the last line mode (last line mode) is also included in the
command mode command mode).
2. Command mode (command mode) function keys
1. Insert mode
Press "i" to switch to insert mode "insert
mode", press "i" to enter insert mode and start inputting files from the current position of the cursor;
press "a" to enter After inserting mode, the text is entered from the next position of the current cursor position; after
pressing "o" to enter the insert mode, a new line is inserted, and text is entered from the beginning of the line.
2. Switch from insert mode to command line mode and
press the "ESC" key.
3. To move the cursor
vi can directly use the cursor on the keyboard to move up and down, left and right, but the regular vi uses lowercase English letters "h", "j", "k", "l" to control the cursor left, down, and up respectively , Move one space to the right.
Three, vi save command.
Press the ESC key to jump to the command mode, and then:
:w save the file but do not exit vi
:w file save the changes to the file additionally, do not exit vi
:w! Force save, do not launch vi
:wq save the file and exit vi
:wq ! Force save the file and exit vi
q: Don't save the file, exit vi
:q! Don't save the file, force exit vi
:e! Discard all changes and start editing from the last time the file was saved.

Guess you like

Origin blog.csdn.net/qq_42000661/article/details/114835100