How to exit VI in linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. You can use one of the following methods to exit Vi and return to shell after editing the file.
In command mode, the upper-case letter Z is used for two connections. If the current edited file has been modified, Vi will save the file and exit, and return to shell; if the current edited file has not been modified, Vi exits directly and returns to shell.
In the last line mode, enter the command
: W
Vi saves the current editing file, 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 file name for the editing file.
: W newfile
At this time, Vi will save the content of the current file to the specified newfile, while the original file remains unchanged. If newfile is an existing file, 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 file, you can use the command
: W! Newfile
Otherwise, you can select another file name to save the current file.
In the last line mode, enter the command
: Q
The system exits Vi and returns to shell. If the editing file is not saved when you exit Vi with this command, the last line of the Vi display window displays the following information:
No write since last change (use! To overrides)
The user is prompted that the file 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 file, 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 file 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.