In Linux, VI/Vim does not have the permission to save files when editing files.

Source: Internet
Author: User

 

 

In a Linux environment, if you directly use the VI/Vim command to edit files without modification permissions, you will be prompted not to save the files, the general solution is to close the file and re-open the file with the sudo permission before saving it (provided that the user has the sudo permission ). In factVI/Vim ModeWith some simple commands, you canSave the current file without closing it (thanks to the method provided by Xiao Zhe ):

    1. Enter the following command:%! Sudo tee %>/dev/null
    2. Enter as promptedSudoPermission Password
    3. Enter"L"(LOad File)
    4. Input: QCommand to exit

About"%! Sudo tee %>/dev/null"This command is described as follows:

% # File content edited by VI/Vim

!# Pipelines

Sudo# Operate with root permission

Tee#Output the standard input (that is, the content of the currently edited file from the MPs Queue) to the standard output, and write it to the specified file (That is, the file currently edited by VI/vim.)

%#Files edited by VI/Vim

>/Dev/null# Redirect standard output/Dev/null (no output)

Related Article

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.