I noticed that vim executes the global vimrc and my personal ~/.vimrc first then followed by syntax files, then plugin .vim files. All too often this causes some of the customizations a user makes in their .vimrc to be overridden by one of these plugins. I have seen this, for example, in formatoptions, iskeyword, etc.
The question is how do I control the order of execution to guarantee that my customizations are applied last and don't get overriden.
I have seen many people asking about how to find the order of execution (:scriptnames), but no one who gave answers tried to address anything about controlling the order of executing these file, when it's obvious that the people asking the question had their changes overridden by some plugin or such.
Put your plugins into ~/.vim/after — they will be sourced after all others.
Some settings should be sourced after the vimrc
file. Filetype specific settings are a prime example of this behavior.
Examples:
$VIMRUNTIME/ftplugin/python.vim
.iskeyword
for lisp like languages should allow -
in words and most other languages should not.Your example settings of 'iskeyword'
& 'formatoptions'
are both buffer local options which should probably should be set on a 'filetype'
by 'filetype'
basis.
If you do want to change these settings for a specific 'filetype'
you can use the after-directory to add your customizations after ftplugins have been sourced.
Example: if you want to add -
to 'iskeyword'
for css files, add the following to your ~/.vim/after/ftplugin/css.vim
file:
setlocal iskeyword+=-
If a plugin is misbehaving then you can use the after-directory as well to make changes after a plugin has been sourced. e.g. ~/.vim/after/plugin/{plugin}.vim
will be sourced after {plugin}
has been sourced.
For more help see:
:h after-directory
:h ftplugin
:h :setlocal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With