Linux tutorial using vi command

1. First, use the vi command to punch in the file to be edited:


 

 

Note: The use of the vi command is as follows:

open or create a new file, and place the cursor at the beginning of the first line: [root@centos6 /]# vi /etc/my.cnf

Open the file and move the cursor to the beginning of the last line: [ root@centos6 /]# vi + /etc/my.cnf

Open the file and place the cursor at the beginning of the nth line: [root@centos6 /]# vi +n /etc/my.cnf

Open the file and place the cursor At the first string matching pattern: vi +/pattern filename


2. Press the "a" key on the keyboard, and after INSERT appears on the vi interface, start editing

 

 

3. After editing, press the ESC key to jump to the command mode, and then save and exit or exit without saving:


save, do not exit vi-------------------- --- :w

force save, do not exit vi ----------------------- :w!

save the changes to file additionally, but do not exit vi ( Not commonly used) ----------------------- :w file

save, and exit vi---------------- ------- :wq or :x

force save and exit vi----------------------- :wq!

~~~~~~ ~~~~~~~~~~~~~~~~~~~~~ Gorgeous dividing line~~~~~~~~~~~~~~~~~~~~~~ ~~~~

The following are related commands that

do not save. Do not save, and exit vi----------------------- :q

Do not save, and force exit vi- ---------------------- :q!

Abandon all changes and start editing from the last time the file was saved------------- ---------- :e!

Guess you like

Origin blog.csdn.net/qq_45534098/article/details/112180014