Vi Exit command (save, discard save)

Source: Internet
Author: User

 

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.

[Example 6]

: 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.

From lovejing007

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.