插件是由 vimrc 加载还是之后加载?

Are plugins loaded by vimrc or afterwards?

我对 Vim 加载插件文件的顺序感到困惑,并且似乎在网上找到了不同的答案。 Some answers seem to suggest that vimrc is loaded before plugins, while others 建议在 vimrc 的采购期间,在第 filetype plugin indent on 行加载它们。有人可以澄清 vimrc、插件和 after/ 目录中的插件的加载顺序,导致每个加载的原因,以及在 vim 会话期间何时可以重新加载每个插件(例如什么再次采购 vimrc 时会发生什么,设置文件类型时会发生什么等等)?

.vimrc在加载插件之前执行:

At startup, Vim checks environment variables and files and sets values accordingly. Vim proceeds in this order:

(...)

  1. 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.

(...)

  1. Load the plugin scripts.

只需使用 :scriptnames 查看所有源文件及其在启动期间的加载顺序。

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.

所有插件都是在你的vimrc之后获取的(正确的术语),除非你手动获取它们。 filetype plugin indent on 行不会对该顺序进行任何更改。

Can someone please clarify the order in which vimrc, plugins, and plugins in the after/ directory are loaded,

假设您的 vimrc 中有 filetype plugin indent on:

  1. 系统vimrc如果有
  2. 你的vimrc.
  3. 内置插件。
  4. 你的插件。
  5. 内置特定于文件类型的插件。
  6. after/ 目录中的内容。

整个事情在 :help startup 中都有解释,并且在 :scriptnames 中可以看得很清楚。

what causes each to load,

一般 &runtimepath 的值和文件类型特定内容的 :filetype 命令。

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 重新执行 vimrc.
  • 中的每个命令
  • 大多数插件的编写方式都可以防止它们被重复获取。如果您想重置它们,请阅读它们的 documentation/code。
  • :help :filetype.