.vimrc 配置文件在使用 'sudo' 编辑时不会加载 [英] .vimrc configuration file does not load when editing with 'sudo'

查看:26
本文介绍了.vimrc 配置文件在使用 'sudo' 编辑时不会加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .vimrc 文件有问题,问题是它有时会被加载,有时不会.

I have problem with .vimrc file, the problem is that it sometimes get loaded, and sometimes not.

  1 set number
  2 syntax on
  3 set autoindent
  4 map <F2> :!g++ % -Wall -time -O<CR>
  5 echo "it works!"

我添加了 echo 来检查它是否已加载,以及何时输入,例如vim .vimrc,它被加载并在终端中显示它有效",但是当我输入例如sudo vim test.cpp 它没有被加载,消息没有显示.我正在使用 debian.

I've added echo to check if it's loaded, and when I type e.g. vim .vimrc, it gets loaded and shows me "it works" in terminal, but when I type e.g. sudo vim test.cpp it doesn't get loaded, the message doesn't show up. I'm using debian.

推荐答案

当您使用 sudo 时,Vim 会在不同的用户 (root) 下启动.由于这个用户有一个不同的 home 目录,另一个 ~/.vimrc 被加载(或者没有,如果那个用户没有).您可以通过多种方式解决问题:

When you use sudo, Vim gets launched under a different user (root). As this user has a different home directory, another ~/.vimrc is loaded (or none, if that user doesn't have one). You can solve the problem in multiple ways:

  1. 您可以直接指定 .vimrc 的位置:sudo vim -u $HOME/.vimrc(不过这对插件没有帮助).
  2. 您可以使用 sudo -e sudoedit.
  3. 你可以为 root 链接你的 .vimrc(和 .vim 插件目录): sudo ln -s $HOME/.vimrc .vimrc;sudo ln -s $HOME/.vim .vim
  4. 您可以将 root 的整个主目录更改为与您的相同(不推荐,因为安全和访问权限!)
  1. You can directly specify the location of your .vimrc: sudo vim -u $HOME/.vimrc (this won't help with plugins, though).
  2. You can use sudo -e <file> or sudoedit.
  3. You can symlink your .vimrc (and the .vim plugins directory) for root: sudo ln -s $HOME/.vimrc .vimrc; sudo ln -s $HOME/.vim .vim
  4. You can change the entire home directory of root to be the same as yours (not recommended, because of security and access rights!)

这篇关于.vimrc 配置文件在使用 'sudo' 编辑时不会加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆