Search code examples
vimvim-pluginftplugin

Are plugins loaded by vimrc or afterwards?


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


Solution

  • 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:

    1. The system vimrc if there is one.
    2. Your vimrc.
    3. Built-in plugins.
    4. Your plugins.
    5. Built-in filetype-specific plugins.
    6. 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 your vimrc.
    • 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.