我试图确保我的neovim
配置适用于所有用户。基本上我希望我的neovim
配置 at~/.config/nvim
用于使用nvim
命令 with sudo
。因此我复制~/.config/nvim
到/etc/xdg/nvim
.
问题是我正在使用astronvim
并且它使用一个init.lua
文件而不是init.vim
.根据这我需要一个sysinit.vim
文件。因此我创建了一个sysinit.vim
文件,但我不确定如何在sysinit.vim
.如何才能实现这一点呢?
答案1
如果您只想通过 sudo 使用 nvim 命令,请保留~/.config/nvim
,则无需创建其他配置文件。
跑步:
sudo -E nvim /path/to/file
或者:
EDITOR=nvim sudoedit /path/to/file
EDITOR=nvim sudo -e /path/to/file
从man sudo
:
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their existing environment variables.
The security policy may return an error if the user does not have permission to preserve the environment.
-e, --edit Edit one or more files instead of running a command. In lieu of a path name, 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.
如果 Neovim在 shell 配置文件中sudoedit /path/to/file
进行了配置,您就可以运行。EDITOR
例子:
# .bashrc
EDITOR=nvim