How to exit vi in ​​linux system

(*-*)浩
Release: 2019-05-30 16:21:27
original
26868 people have browsed it

In Linux, the vim editor is the text editor that comes with the system, but to modify a text file, it is not like Windows. Even newbies, after entering the vi editor, cannot exit and force shutdown. , in fact, this vim (vi) is also very simple.

How to exit vi in ​​linux system

1. Enter the vim editor

vim editor. You can create new files or modify files. The command is: vim / usr/local/con.cfg

If this file did not exist before, it will be newly created, and there will be a prompt below that it is a new file. If the file already exists, there will be no prompt.

After entering the editor, we first press "i" to switch to the "insert" state. You can edit content by moving the cursor up, down, left, and right, space, backspace, and enter, just like Windows.

2. Methods and differences in exiting the vim editor

After text editing is completed, you usually need to exit the editor. Exiting the editor is divided into 4 situations: Save and exit, exit normally, exit without saving and force exit.

① Save and exit

When we have edited or modified the file content, of course we have to save and exit and then proceed to the next step. At this time, we have to press "ESC" in the upper left corner of the keyboard. Did you notice? The insertion status in the lower left corner is gone. Then, at this time, we enter "colon", that is, ":" (without double quotes). A colon will appear below, waiting for the command to be entered. Enter "wq". The function is as follows:

w: write, write

q: quit, exit

and press Enter to save and exit.

Actually, there are two ways to save and exit:

A: When entering the last command, directly enter "x", which is the same, that is: x= wq.

B: The fastest way: after pressing ESC, directly press shift zz or switch to uppercase mode and press ZZ to save and exit, that is, press the uppercase Z twice.

We can use the view command cat to view its content: cat /usr/local/con.cfg.

② Normal exit

There is a prerequisite for normal exit: the content of the open text file has not been changed. Press ESC and then enter "colon". When entering commands, enter "q" directly.

③ Exit without saving

Many times I open a file or modify some places, only to find something wrong and need to exit without saving. Press ESC first, then enter "colon". When entering the command, enter "q!" directly.

④ Force exit

For less commonly used operations, press ESC first, then press "colon". When entering a command, directly enter "!" and exit. , there will be a prompt!

Note: Linux commands must be lowercase!

The above is the detailed content of How to exit vi in ​​linux system. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!