Vim in Linux save root permissions file

Source: Internet
Author: User

Linux is often encountered with vim edited the file, save when prompted the current file is read-only.

E45: ' readonly ' option is set (add! To override)

The reason is also simple, because the user does not have write permission to the currently edited file, a possible solution is to use the sudo command to open the file again to edit, but in this case, the previous editing work will need to be all over again, how to forget to use sudo Vim edits a file that is not writable by itself, and still writes the file normally?

The strength of vim is reflected, the following instructions easy to handle

: w!sudo Tee%

Here's what the command uses

: w!sudo Tee%
[sudo] password for xxxx:
...
...
...

Press ENTER or type command to continue

After the carriage return will prompt the file has changed, press O or L reload again just fine.

W12:Warning:File "XXX" has changed and the buffer is changed in Vim as OK
": Help W12" for more info.
O K, (L) oad File:

Command interpretation

: W is Vim's write command
% currently edited file name
!sudo Tee VIM calls the shell command in the!
The entire command is to run the tee command as root, to read the output of the VIM:W command as a standard input, to output its contents to a standard output device, and to save it to a%-represented file

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.