如果您在vi或vim中打开文件并且没有写入权限,是否有办法sudo su
而无需丢弃所有更改并重新打开?
目前,我必须放弃所有更改,关闭vi,然后关闭su vi
。
答案 0 :(得分:1)
如果您安装the Sudo Edit plugin,则会收到命令:SudoWrite
,该命令会询问您的root密码。然后它将以root身份写入文件,非常方便。我经常用它来编辑/ etc /.
来自文档:
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.