What is the difference between
$VIMRUNTIME/default.vim started first?
/etc/vim/vimrc leave first?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
/etc/vim/vimrc is a system-wide default Vim configuration added by the corresponding package maintainers (e.g. the Debian folks for the vim-common APT package). It represents the opinion of the distribution's maintainers about good (and secure) defaults.
For a long time, Vim itself didn't provide any default configuration; instead, it just shipped with an example (
:help vimrc_example.vim) to get individual users started on their personal configuration (i.e.
~/.vimrc). Many people did not like that Vim starts with conservative defaults (for vi compatibility), and the "helpful" system-wide configuration also caused confusion (as Vim has so many configuration possibilities and flexibility), and so with Vim 8.0 a default configuration in the form of
defaults.vim was added.
Your question hints at confusion with that configuration. In general, if the defaults don't work for you, do all your customization in your user's
~/.vimrc, and leave any system-wide configuration alone. Those should only make uncontroversial changes (like
:syntax on), so that should not interfere, but most option changes can also be undone by your
/etc/vim/vimrc is the so-called "system" vimrc file (it should be listed as so in your
$VIMRUNTIME/defaults.vim is the "defaults" file, which was only introduced in Vim 8.0 (at least, that was the first non-patch release to include the feature.)
/etc/vim/vimrc is controlled by the Linux distribution, so Debian or Red Hat, etc. will ship Vim initialization they find is relevant for your distribution there.
defaults.vim is loaded automatically only if you don't have a user vimrc file. So only if your user is missing a
~/.vim/vimrc file. If you do have one of these files, then
defaults.vim will not be loaded automatically, though you might want to do it from your vimrc.
The system vimrc file is always loaded and it's always loaded first. (Well, unless you pass Vim command-line options telling it not to load the vimrc files, such as
vim -u NORC or
-u NONE, in which case it isn't loaded.)
After the system vimrc is processed, then it's turn for your own vimrc file, or
defaults.vim if your own doesn't exist.
Now, there are two important caveats here!
First is that
defaults.vim might have been disabled (more like neutered) by your distribution. Some distributions (namely Debian) weren't too happy about Vim shipping a
defaults.vim file that would enable settings that users upgrading from previous versions weren't expecting.
So this was solved by having the Vimscript code in
defaults.vim check whether a variable named
skip_defaults_vim has been set. If it is, then
defaults.vim will bail out early on and you won't really see its effects. (Note that the script will still appear under
:scriptnames, since it does get to run, it just finishes very early.)
Since the only thing running before
defaults.vim is the system vimrc file, that's the place where
skip_defaults_vim can be set. So check whether your distribution is setting it, if it is, then you won't really get the effects of
defaults.vim even when the file is being sourced.
Second caveat, and a point of frequent confusion, is when you first create a new vimrc file for your user. Then you go from having all the settings in
defaults.vim loaded to having none of them. Which is quite visually apparent, since it typically means you won't have syntax highlighting enabled anymore, which is pretty much in your face, you can quickly notice the difference.
The recommendation here is that, when you first create a vimrc file, you should source
defaults.vim from it, so you'll keep the features from it and then you can add your own customization later.
You can do that by adding these two lines to the start of your vimrc file:
unlet! skip_defaults_vim source $VIMRUNTIME/defaults.vim
Notice it's also unsetting
skip_defaults_vim, which means this will activate the
defaults.vim settings even on Linux distributions that have decided to disable the effects of that file.
vimrc_example.vim file shipped with Vim (which is provided as a template to use to create your own vimrc) includes a line that sources
defaults.vim at the top.
For more information, see: