1

如果您在 vi 或 vim 中打开文件并且没有写入权限,有没有办法sudo su不必放弃所有更改并重新打开?

目前,我必须放弃所有更改,关闭 vi 然后su vi.

4

1 回答 1

1

如果您安装Sudo Edit 插件,您: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.
于 2013-02-08T20:10:12.240 回答