0

What is the difference between $VIMRUNTIME/default.vim and /etc/vim/vimrc?

Why is $VIMRUNTIME/default.vim started first? Shouldn't /etc/vim/vimrc leave first?

(Debian 9)

  • 2
    Could you add some information on which Linux flavor and version you are using? In Debian-based systems, e.g., /etc/vim/vimrc sources the settings from the $VIMRUNTIME directory. – AdminBee Mar 5 at 15:52
  • Done...debian 9 – vincenzogianfelice Mar 5 at 16:14
  • What does The Fine Manual say? – vonbrand Mar 5 at 20:37
3

/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 ~/.vimrc.

In terms of the order of configuration reads, :scriptnames shows what scripts got read in which order, and :help initialization has all the gory details.

| improve this answer | |
  • So, is default.vim first launched which in turn launches /etc/vim/vimrc...correct? – vincenzogianfelice Mar 5 at 16:26
  • I read that guide ... but /etc/vim/vimrc is not really mentioned – vincenzogianfelice Mar 5 at 16:37
  • 1
    As I said, it depends on your particular system. Check :scriptnames for the ordering, or maybe start Vim with --cmd 'set verbose=2' to see what's happening in detail. – Ingo Karkat Mar 5 at 17:24
0

File /etc/vim/vimrc is the so-called "system" vimrc file (it should be listed as so in your :version output.)

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

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

File defaults.vim is loaded automatically only if you don't have a user vimrc file. So only if your user is missing a ~/.vimrc or ~/.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.

The 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:

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.