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