简体   繁体   English

_vimrc 他的主目录覆盖 $VIM 中的 _vimrc

[英]_vimrc him home directory overrides _vimrc in $VIM

On Linux, when I create a ~/.vimrc file it extends the system settings, in the sense that it runs the commands in my ~/.vimrc file without changing any settings that are not in my file.在 Linux 上,当我创建一个~/.vimrc文件时,它会扩展系统设置,因为它运行我的~/.vimrc文件中的命令而不更改我的文件中没有的任何设置。

On Windows it appears that the %HOMEPATH%\_vimrc file overrides other settings files, since even adding a blank one completely changes the behaviour of vim.在 Windows 上, %HOMEPATH%\_vimrc文件似乎覆盖了其他设置文件,因为即使添加空白文件也会完全改变 vim 的行为。

Is this the expected behaviour on Windows?这是 Windows 的预期行为吗? Do I need to copy the other settings files into my home directory if I want to extend them?如果我想扩展其他设置文件,是否需要将它们复制到我的主目录中?

This is how Vim works: if you don't have vimrc it loads $VIMRUNTIME/defaults.vim instead;这就是 Vim 的工作方式:如果你没有vimrc ,它会加载$VIMRUNTIME/defaults.vim if you do have then it does not.如果你有那么它没有。

What was your issue on Linux, it's you who should know better.您在 Linux 上遇到了什么问题,您应该更清楚。 Maybe it was system's /etc/vimrc , maybe it was Neovim, etc.也许是系统的/etc/vimrc ,也许是 Neovim 等。

If you ever want to add the settings from defaults.vim , just do runtime defaults.vim如果您想从defaults.vim添加设置,只需执行runtime defaults.vim

Vim versions 8 and above (which is probably what you're using) ship a defaults.vim file that is used whenever a user vimrc file is not found. Vim 版本 8 及更高版本(这可能是您正在使用的)附带一个defaults.vim文件,该文件在找不到用户 vimrc 文件时使用。 The defaults.vim file enables filetype detection and syntax highlighting, among other settings that are considered useful for all or most Vim users. defaults.vim文件启用文件类型检测和语法突出显示,以及被认为对所有或大多数 Vim 用户有用的其他设置。 See :help defaults.vim for more details.有关详细信息,请参阅:help defaults.vim

So this is what you're seeing on Windows, where you install a Vim package from the official website and you get the default Vim behavior.所以这就是您在 Windows 上看到的内容,您在其中安装了 Vim package 从官方网站获得默认的 Z944037673FD3 行为。 For backwards compatibility, the defaults.vim behavior only happens if you don't have a user vimrc file ( %HOMEPATH%\_vimrc ) at all, or if you include it explicitly.为了向后兼容, defaults.vim行为仅在您根本没有用户 vimrc 文件 ( %HOMEPATH%\_vimrc ) 或明确包含它时才会发生。

The recommendation is to load it explicitly when you start a new vimtex file, with the two lines at the top:建议在启动新的 vimtex 文件时显式加载它,顶部有两行:

unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim

The reason why you might not see this on Linux is that some Linux distributions (namely Debian, possibly Ubuntu which inherits many Debian packages) decided they didn't like the defaults.vim behavior, particularly the part of it not getting enabled if the user vimrc file exists. The reason why you might not see this on Linux is that some Linux distributions (namely Debian, possibly Ubuntu which inherits many Debian packages) decided they didn't like the defaults.vim behavior, particularly the part of it not getting enabled if the user vimrc 文件存在。 (Which is understandable, you've seen the confusion it brings when you create an empty vimrc file and Vim suddenly behaves different and a lot of stuff gets disabled!) (这是可以理解的,当您创建一个空的 vimrc 文件并且 Vim 突然表现不同并且很多东西被禁用时,您已经看到了它带来的混乱!)

So they ship a system vimrc file /etc/vimrc that does many of the stuff the defaults.vim file does (such as enabling filetype detection and syntax highlighting) and then disable the defaults.vim behavior altogether (by setting the skip_defaults_vim variable.) So in those distributions you don't get the defaults.vim behavior unless you include it explicitly (and only if you first unlet the variable that disables it.) On the other hand, you always get similar or equivalent settings from the system vimrc file shipped by the distribution.因此,他们发布了一个系统 vimrc 文件/etc/vimrc来完成许多defaults.vim文件所做的事情(例如启用文件类型检测和语法突出显示),然后完全禁用defaults.vim行为(通过设置skip_defaults_vim变量。)因此,在这些发行版中,您不会获得defaults.vim行为,除非您明确包含它(并且仅当您首先解除禁用它的变量时。)另一方面,您总是从系统 vimrc 文件中获得类似或等效的设置由配送配送。

My recommendation is that you enable the defaults.vim behavior in your vimrc file, which works in all platforms and all Linux distributions.我的建议是在 vimrc 文件中启用defaults.vim行为,该行为适用于所有平台和所有 Linux 发行版。 It also includes some useful settings that are not present in the /etc/vimrc of Linux distributions that disable the defaults.vim behavior, so it might be useful there as well.它还包括一些有用的设置,这些设置在 Linux 发行版的/etc/vimrc中不存在,这些设置会禁用defaults.vim 。vim 行为,因此它在那里也可能有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM