Vim E212: Solution that cannot be opened and written to a file

Source: Internet
Author: User
Tags save file

When writing a configuration file, often forget to switch to root, resulting in file editing, typing: Wq exit save, appear E212: Unable to open and write file error prompts. This is due to the fact that the current user does not have write permissions in this directory.

The solution is as follows:

"1" Saves the file to the user directory, changes the owner, and moves to the configuration directory as follows:

1 Save exit with : Wq! ~/tmp/file.conf

2 su switch to root user, will file.conf change the owner, chown Root file.conf

3) Mobile configuration file to target directory,MV file.conf [pathname]

The second solution of "2" is relatively simple

Save file with : W! sudo tee%

Tee is used to read input files while saving

% represents the current edit file

(however, one requirement for this approach is that the current editing user must be in the Sudoers file, which is also required to execute the sudo command)

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.