If you open a file in vi or vim and dont have permissions to write, is there a way to sudo su
without having to discard all changes and reopen?
Currently, I have to discard all changes, close vi and then su vi
.
If you open a file in vi or vim and dont have permissions to write, is there a way to sudo su
without having to discard all changes and reopen?
Currently, I have to discard all changes, close vi and then su vi
.
If you install the Sudo Edit plugin you get the command :SudoWrite
which will ask you for your root password. It will then write the file as root, it's very convenient. I use it frequently for editing things in /etc/.
From the documentation:
2.2 SudoWrite *SudoWrite*
:[range]SudoWrite[!] [file]
SudoWrite will write the given file using any of the configured methods for
superuser authtication. It basically does something like this: >
:w !sudo tee >/dev/null file
If no filename is given, SudoWrite will try to write the current file name.
If the current buffer does not contain any file, it will abort.
You can specify a range to write just like |:w|. If no range is given, it will
write the whole file. If the bang argument is not given, the buffer will only
be written, if it was modified.
Again, you can use the protocol handler sudo: for writing.