Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vim how do I change the order that scriptnames get sourced?

Tags:

vim

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.

like image 533
AZAhmed Avatar asked Jan 21 '18 21:01

AZAhmed


2 Answers

Put your plugins into ~/.vim/after — they will be sourced after all others.

like image 170
phd Avatar answered Oct 26 '22 23:10

phd


Some settings should be sourced after the vimrc file. Filetype specific settings are a prime example of this behavior.

Examples:

  • Python's pep8 indention settings which are found in $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
like image 28
Peter Rincker Avatar answered Oct 26 '22 23:10

Peter Rincker