如果你在vi或vim中打开一个文件,但没有写的权限,有没有一种方法可以在不放弃所有更改并重新打开的情况下使用sudo su?
目前,我必须放弃所有更改,关闭vi,然后关闭su vi。
发布于 2013-02-09 04:10:12
如果你安装了the Sudo Edit plugin,你会得到命令:SudoWrite,它会要求你输入根密码。然后它将以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.https://stackoverflow.com/questions/14780457
复制相似问题