Regis May
Regis May

Reputation: 3466

In which order does VIM load which configuration file?

I just found some stackoverflow answers to questions regarding VIM and was very much confused why configuration parameters I set did not work as recommended in these answers. It turned out that they simply got overwritten but other VIM configuration files I was not aware of! So I'm wondering:

a) In which order does VIM load which configuration file? (If I learn about this I will likely be able to address the next question.)

b) I want to load all defaults and then enable/disable specifically some few settings. In which configuration file do I have to define this?

Please have in mind that I am trying to avoid wild hacking in the configuration files. The next system update will likely overwrite them. Therefor I'm trying to find a way of how to make use of /etc/vim/vimrc.local or similar configuration files in order to overwrite all existing settings. But this is of no use if other configuration files are loaded after /etc/vim/vimrc.local has been loaded. In order to achieve this I attempted to load /usr/share/vim/vim80/defaults.vim explicitly within /etc/vim/vimrc.local and then set g:skip_defaults_vim to 1 explicitly to avoid VIM to load it again at a later time. Which - as I can see - does not work as my own settings from /etc/vim/vimrc.local get overwritten. But if I load /etc/vim/vimrc.local explicitly from within a running VIM instance my settings don't get overwritten. Which I find quite confusing. Does anyone have an idea about that? Any help is appreciated!

Upvotes: 1

Views: 3748

Answers (2)

Regis May
Regis May

Reputation: 3466

In my case I was able to track down the problem and solve it.

I guess it's a bit more complex but basically that's what's going on in Debian based systems:

  • First /etc/vim/vimrc seems to be loaded. The directory /etc/vim seems to be symlinked from /usr/share/vim/vim80.
  • Within v/etc/vim/vimrca file nameddebian.vim` is loaded.
  • Then within /etc/vim/vimrc the file /etc/vim/vimrc.local is loaded. That's where I want to make my changes it is intended to be the place for that.
  • In this file I source /usr/share/vim/vim80/defaults.vim to load the defaults provided by the package maintainer. Then I set g:skip_defaults_vim to 1 to prevent vim to load these defaults later again.
  • After this within /usr/vim/vimrc.local I set all system wide defaults.

If I now run vim some of the defaults aren't in effect. I can explicitly set them within vim to enable them. Or - strangely - not load defaults.vim. Within "defaults.vim" the file type indentation plugin is loaded which causes undesired behavior I don't manage to overwrite within /usr/vim/vimrc.local . If I turn off this plugin any defauls made are in effect as expected. It seems that this plugin overrides defaults set if specific files are going to be edited after all other configurations are accepted by vim already.

So there is a simple solution: Turn off this plugin by adding this line to /etc/vim/vimrc.local:

filetype plugin indent off

A better approach would be to reconfigure the plugin of course, but for simplicity I won't go that far for now.

Upvotes: 1

romainl
romainl

Reputation: 196789

  1. $ mkdir ~/.vim and add any custom or third-party scripts to that directory, creating subdirectories as needed.
  2. $ touch ~/.vim/vimrc and set your options and mappings and whatnot in that file.
  3. Don't do anything vim-related outside of that directory.
  4. Everything is explained in detail in :help startup.

Upvotes: 5

Related Questions