为什么Vim不提供我的.vimrc文件


9

今天,我发现我.vimrc没有生效。几小时前还可以。

当我用启动vim时$vim --plugin:scriptnames没有回声:.vimrc文件不是源文件。(注意:/etc/vimrc已删除,以调试此问题。)

然后,我尝试使用google并发现$VIMINIT变量可疑。

这是值$VIMINIT

$ echo $VIMINIT
set number

Vim文档VIMINIT

 c. Four places are searched for initializations.  The first that exists
    is used, the others are ignored.  The $MYVIMRC environment variable is
    set to the file that was first found, unless $MYVIMRC was already set.
    -  The environment variable VIMINIT (see also |compatible-default|) (*)
       The value of $VIMINIT is used as an Ex command line.
    -  The user vimrc file(s):
                "$HOME/.vimrc"      (for Unix and OS/2) (*)
                "s:.vimrc"          (for Amiga) (*)
                "home:.vimrc"       (for Amiga) (*)
                "$VIM/.vimrc"       (for OS/2 and Amiga) (*)
                "$HOME/_vimrc"      (for MS-DOS and Win32) (*)
                "$VIM/_vimrc"       (for MS-DOS and Win32) (*)
            Note: For Unix, OS/2 and Amiga, when ".vimrc" does not exist,
            "_vimrc" is also tried, in case an MS-DOS compatible file
            system is used.  For MS-DOS and Win32 ".vimrc" is checked
            after "_vimrc", in case long file names are used.
            Note: For MS-DOS and Win32, "$HOME" is checked first.  If no
            "_vimrc" or ".vimrc" is found there, "$VIM" is tried.
            See |$VIM| for when $VIM is not set.
    -  The environment variable EXINIT.
       The value of $EXINIT is used as an Ex command line.
    -  The user exrc file(s).  Same as for the user vimrc file, but with
       "vimrc" replaced by "exrc".  But only one of ".exrc" and "_exrc" is
       used, depending on the system.  And without the (*)!

我无法完全理解vim文档。似乎$VIMINIT可能会破坏vim的启动。

清除$VIMINIT

$ VIMINIT=
$ echo $VIMINIT

问题仍然存在。


2
“使用存在的第一个,其他被忽略。” $VIMINIT优先于任何.vimrc文件。它满足先到先得的规则。因此,是的.vimrc被忽略。
Sukima

Answers:


10

扩展@mMontu的答案;Vim按照该列表的顺序搜寻初始化,直到找到一个。由于$VIMINIT变量优先于.vimrc文件,因此它满足了搜索要求,并且忽略了该选项之后的任何其他选项。

之后仍然无法正常工作的原因:

$ VIMINIT=
$ echo $VIMINIT

是(1)您正在设置局部变量而不是环境变量。那需要导出:

$ export VIMINIT=

(2)仍然无法使用,因为VIMINIT它仍然被定义:

$ printenv | grep VIMINIT
VIMINIT=

需要发生的是一起从环境中清除:

$ unset VIMINIT
$ printenv | grep VIMINIT || echo "Gone"
Gone

(这些命令是特定于Bash的。如果需要,请更改它们以适合您的首选Shell。)


但这仅适用于会话,确定取消设置该怎么办?还是搜索变量集在哪里,以便您可以删除它?
冯玉

8

您可能误解了文档:

 c. Four places are searched for initializations.  The first that exists
    is used, the others are ignored.

因此,如果您使用的是VIMINIT,则不会加载vimrc。

-  The environment variable VIMINIT (see also |compatible-default|) (*)
   The value of $VIMINIT is used as an Ex command line.

您正在将$ VIMINIT设置为Ex命令,set number根据文档,该命令还可以。但是,如果更喜欢vimrc,则应set number在该文件中包含它,而不要使用$ VIMINIT。您提到将其设置为空,并且vimrc仍未加载,但实际上应该取消设置该变量。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.