I'm confused about the order in which Vim loads plugin files, and seem to be finding mixed answers online. Some answers seem to suggest that vimrc is loaded before plugins, while others suggest that they are loaded during the sourcing of vimrc, at the line filetype plugin indent on. Can someone please clarify the order in which vimrc, plugins, and plugins in the after/ directory are loaded, what causes each to load, and when each could be reloaded during a vim session (e.g. what happens when sourcing vimrc again, what happens when setting the filetype, etc.)?
Are plugins loaded by vimrc or afterwards?
1.8k Views Asked by Kvass At
3
There are 3 best solutions below
3
On
.vimrc is executed before loading plugins:
At startup, Vim checks environment variables and files and sets values accordingly. Vim proceeds in this order:
(...)
- Execute Ex commands, from environment variables and/or files An environment variable is read as one Ex command line, where multiple commands must be separated with '|' or "". vimrc exrc A file that contains initialization commands is called a "vimrc" file. Each line in a vimrc file is executed as an Ex command line.
(...)
- Load the plugin scripts.
All plugins are sourced (the correct term) after your
vimrcunless you source them manually. Thefiletype plugin indent online doesn't change anything to that order.Assuming you have
filetype plugin indent onin yourvimrc:vimrcif there is one.vimrc.after/directory.The whole thing is explained in
:help startupand can be seen very clearly with:scriptnames.The value of
&runtimepathin general and the:filetypecommand for filetype-specific stuff.:source $MYVIMRCre-executes each command in yourvimrc.:help :filetype.