Run the VIM exit command and run the vim exit command.
Note: These commands are preceded by a colon:
You can use either of the following methods to exit Vi and return to shell after editing the document.
In command mode, two uppercase letters are used for a connection. If the edited document has been modified, Vi saves the document and exits, and returns to shell; if the edited document has not been modified, Vi exits and returns to shell.
In the last line mode, enter the command
: W
Vi saves the current edited document, but does not exit, but continues waiting for the user to enter the command. When you use the w command, you can create a new document name for editing the document.
[Example 6]
: W newfile
At this time, Vi will save the content of the current document to the specified newfile, while the original document remains unchanged. If newfile is an existing document, the Vi prompts in the status line of the display window:
File exists (use! To override)
If you really want to replace the original content in newfile with the current content of the document, you can use the command
: W! Newfile
Otherwise, you can select another document name to save the current document.
In the last line mode, enter the command
: Q
The system exits Vi and returns to shell. If you exit Vi with this command and the editing document is not saved, the last line of the Vi display window will display the following information:
No write since last change (use! To overrides)
The user is prompted that the document is not saved after modification, and then Vi does not exit, continue waiting for the USER command. If you want to force exit Vi without saving the modified document, you can use the command
: Q!
Vi abandons the modification and directly returns it to shell.
In the last line mode, enter the command
: Wq
Vi will save the document first, and then exit Vi and return to shell.
In the last line mode, enter the command
: X
This command has the same functions as the ZZ command in command mode.