If you do not have the permission to edit files using vim

Source: Internet
Author: User
Save a file you edited in VIM without the needed permissions (no echo) Address: http://www.commandlinefu.com/commands/view/5147/save-a-file-you-edited-in-vim-without-the-needed-permissions-no-echoSave a file you edited in VIM without the needed permissions (no echo)

Write a file you edited in VIM but that you do not have the permissions to write to (unless you use sudo.) Same as #1204 but without the echo to stdout that I find annoying.

You don't need to use sudo to save a file that requires editing permission and save a file that you are writing. You find that you have no permission to write (unless you use SUDO ), use the following command to solve the problem:

The following command explains how to write a file to a command. Tee reads stdin and writes it to stdout and the file. Because sudo is used, you can write it back to the file, for personal testing, you do not need to>/dev/null. You can also directly stdout to the file: W! Sudo tee>/dev/null % Article Comments: W! Sudo tee % save
A file you edited in VIM without the needed permissions

I often forget to sudo before editing a file I don't have write permissions on. when you come to save that file and get the infamous "e212: Can't open file for writing ", just issue that Vim command in order to save the file without the need to save it to
Temp File and then copy it back again.

Command W: Execute ': silent W! Sudo tee %>/dev/null' |: Edit!
Save a file you edited in VIM without the needed permissions

CILS sudo tee like all the other lines, but also automatically reloads the file.

Optionally you can add

Command WQ: Execute ': W' |: Q

And

Command WQ: WQ

To make quitting easier

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.