Linux command to exit the vi editor: 1. Use the ":wq" or ":x" or "ZZ" command to save and exit; 2. Use the ":q" command to exit normally; use ":q!" can exit without saving; 4. Use ":!" to force exit.
#The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.
In Linux, the vim editor is the text editor that comes with the system. However, modifying a text file is not like Windows. Even newbies cannot exit the vi editor after entering it. As for forced shutdown, in fact, this vim (vi) is also very simple.
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. Divided into 4 situations: save and exit, normal exit, exit without saving and forced 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 insert state in the lower left corner is gone, and now we have entered the command mode
Then, we enter a "colon", that is, ":" (without double quotes), and a colon will appear below, Wait for the input command, enter "wq", the function is as follows:
w: write, write
q: quit, exit
and press Enter to save and exit. In fact, 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!
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of What is the command to exit the vi editor in Linux?. For more information, please follow other related articles on the PHP Chinese website!