简体   繁体   中英

_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.

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.

Is this the expected behaviour on 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; if you do have then it does not.

What was your issue on Linux, it's you who should know better. Maybe it was system's /etc/vimrc , maybe it was Neovim, etc.

If you ever want to add the settings from defaults.vim , just do 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. The defaults.vim file enables filetype detection and syntax highlighting, among other settings that are considered useful for all or most Vim users. See :help defaults.vim for more details.

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. 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.

The recommendation is to load it explicitly when you start a new vimtex file, with the two lines at the top:

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. (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!)

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.

My recommendation is that you enable the defaults.vim behavior in your vimrc file, which works in all platforms and all Linux distributions. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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