Linux VI Save Exit command (how to exit VI)

Source: Internet
Author: User
Tags exit

There are many ways:

Exit VI

When you are finished editing a file, you are ready to exit VI when you return to the shell, you can use one of the following methods.

In command mode, even press two Capitals Z, if the currently edited file has been modified, vi save the file exit, return to the shell, if the current edited file has not been modified, then VI directly exit, return to the shell.

In last line mode, enter the command

: W

VI saves the current edit file, but does not exit, but continues to wait for the user to enter the command. When you use the W command, you can then give the edit file a new file name.

[Example 6]

: w NewFile

At this time VI will save the contents of the current file to the specified NewFile, and the original file remains unchanged. If the newfile is an existing file, the VI gives the hint message in the status line of the display window:

File exists (use! To override)

At this point, if the user really want to use the current content of the file to replace NewFile Central has content, you can use the command

: w! NewFile

Otherwise, you can select a different file name to save the current file.

In last line mode, enter the command

: Q

The system exits VI and returns to the shell. If the edit file is not saved when you exit VI with this command, the VI displays the following information at the last line of the display window:

No write since last change (use! to overrides)

Prompts the user that the file was modified without saving, then VI does not exit, and continues to wait for user commands. If the user simply does not want to save the modified file and forced to exit VI, you can use the command

: q!

VI give up the changes and go straight to the shell.

In last line mode, enter the command

: Wq

VI will first save the file, and then Exit VI to return to the shell.

In last line mode, enter the command

: X

This command has the same functionality as the ZZ command in command mode.

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.