关于linux:Vi escelate用户权限

Vi escelate user permission

本问题已经有最佳答案,请猛点这里访问。

如果您在vi或vim中打开一个文件,并且没有写权限,那么有没有一种不必放弃所有更改并重新打开的方法来访问sudo su

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


如果安装sudo edit插件,您将获得命令:SudoWrite,该命令将要求您输入根密码。然后它将文件作为根文件写入,这非常方便。我经常用它来编辑/etc/中的内容。

从文档中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.