如何使用 vim plugin:emmet-vim 和 sudo?

How to use vim plugin:emmet-vim with sudo?

emmet-vim 普通用户就是这样安装的

mkdir .vim
mkdir .vim/plugin
mkdir .vim/autoload

git clone https://github.com/mattn/emmet-vim.git
cd emmet-vim
cp plugin/emmet.vim ~/.vim/plugin/
cp autoload/emmet.vim ~/.vim/autoload/
cp -a autoload/emmet ~/.vim/autoload/

用普通用户打开vim输入:scriptnames

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim74/debian.vim
  3: ~/.vimrc
  4: ~/.vim/plugin/emmet.vim
  5: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
  6: /usr/share/vim/vim74/plugin/gzip.vim
  7: /usr/share/vim/vim74/plugin/matchparen.vim

打开sudo vim,用root用户输入:scriptnames

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim74/debian.vim
  3: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
  4: /usr/share/vim/vim74/plugin/gzip.vim
  5: /usr/share/vim/vim74/plugin/matchparen.vim

普通用户可以使用emmet提供的所有功能
root用户无法使用emmet提供的所有功能
如何使用 vim plugin:emmet-vim 与 sudo ?

使用sudoedit。确保您的 $EDITOR 变量设置正确。

sudoedit 等同于 运行 sudo -e,后者创建文件的临时副本。进行更改后,文件将被复制回原始位置。这允许您使用自己的编辑器配置文件而不是根用户的。

来自手册页:

-e' The -e (edit) option indicates that, instead of running a command, the user wishes to edit one or more files. In lieu of a command, the string "sudoedit" is used when consulting the security policy. If the user is authorized by the policy, the following steps are taken:

  1. Temporary copies are made of the files to be edited with the owner set to the invoking user.

  2. The editor specified by the policy is run to edit the temporary files. The sudoers policy uses the SUDO_EDITOR, VISUAL and EDITOR environment variables (in that order). If none of SUDO_EDITOR, VISUAL or EDITOR are set, the first program listed in the editor sudoers(5) option is used.

  3. If they have been modified, the temporary files are copied back to their original location and the temporary versions are removed.

If the specified file does not exist, it will be created. Note that unlike most commands run by sudo, the editor is run with the invoking user's environment unmodified. If, for some reason, sudo is unable to update a file with its edited version, the user will receive a warning and the edited copy will remain in a temporary file.