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

- 8,294
- 12
- 65
- 108
-
In doubt, you can always add some `:echomsg "I'm here!"` here and `:echomsg "I'm there!"` there. – Luc Hermitte Mar 16 '17 at 08:57
3 Answers
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.
All plugins are sourced (the correct term) after your vimrc
unless you source them manually. The filetype plugin indent on
line doesn't change anything to that order.
Can someone please clarify the order in which vimrc, plugins, and plugins in the after/ directory are loaded,
Assuming you have filetype plugin indent on
in your vimrc
:
- The system
vimrc
if there is one. - Your
vimrc
. - Built-in plugins.
- Your plugins.
- Built-in filetype-specific plugins.
- Stuff in the
after/
directory.
The whole thing is explained in :help startup
and can be seen very clearly with :scriptnames
.
what causes each to load,
The value of &runtimepath
in general and the :filetype
command for filetype-specific stuff.
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.)?
:source $MYVIMRC
re-executes each command in yourvimrc
.- Most plugins are written in a way that prevent them from being sourced twice. Read their documentation/code if you want to reset them.
:help :filetype
.

- 186,200
- 21
- 280
- 313
-
The help describes `filetype plugin on` and `filetype indent on` as loading files. What is the distinction between loading them and sourcing them? – Kvass Mar 16 '17 at 09:56
-
1You just spotted a discrepancy in the doc. Sadly that's not the only one. – romainl Mar 16 '17 at 10:21
.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.

- 6,331
- 16
- 30
-
Can you explain then what the effect of that filetype line is? The answer I linked in my question says that it loads ftplugin and indent files. Is that wrong? Please elaborate on this answer to more fully answer the question before I accept. – Kvass Mar 16 '17 at 07:18
-
1Your question is broad in that case. Why not reading `:help filetype` for more about the command. – Meninx - メネンックス Mar 16 '17 at 08:05
-
I did read the help, as well as other stack overflow answers and blog posts on the topic. I asked because after that I'm still confused :/ If my question seems too broad maybe I can clarify where my confusion is? – Kvass Mar 16 '17 at 08:11
Just use :scriptnames
to see all the sources files and their order in which they are loaded during startup.

- 10,969
- 2
- 30
- 42
-
This won't tell whether the plugins are loaded by the .vimrc (IOW while .vimrc is being sourced), or after. – Luc Hermitte Mar 16 '17 at 08:55