2

What is the plugin system ?

I could not find answers how the plugins are actually loaded/executed in Vim. I know that Vim looks for them in specific locations. I also found this question about what an plugin is and this one about the load sequence of plugins.

So if someone could point me towards some reference on how it works under the hood or what the relevant code is that I can read, it would be highly appreciated!

An overview would be good as well.

1
  • I have edited the title just to avoid some confusion.
    – noobman
    Commented May 6, 2022 at 14:32

1 Answer 1

2

About plugin a good introduction is Learn Vimscript the Hard Way.

In particular the chapter 42: Plugin Layout in the Dark Ages will give you the role of the different folders and files.

Here is my understanding:

The first script to be loaded is .vimrcif it exists:

  1. .vimrc

When Vim starts it executes the following scripts (from: vimfiles, your installed plugins, Vim distribution plugins):

  1. plugin/*.vim
  2. ftdetect/*.vim

Then in executes the following scripts (from: vimfiles, your installed plugins, Vim distribution plugins):

  1. after/plugin/*.vim

When Vim loads a file of type: mytype it executes the following scripts (from: vimfiles, your installed plugins, Vim distribution plugins):

  1. ftplugin/mytype.vim
  2. after/ftplugin/mytype.vim
  3. indent/mytype.vim
  4. after/indent/mytype.vim
  5. syntax/mytype.vim
  6. after/syntax/mytype.vim

When Vim calls a function myscript#myfunction it executes the following scripts searching for the myscript#myfunction (from: vimfiles, your installed plugins, Vim distribution plugins):

  1. autoload/myscript.vim

There are two other folders with special meaning.

The script colors/mycolor.vim is executed when the command :colorscheme mycolor is executed.

When the command :compiler mycompiler is executed Vim executes the following scripts (from: Vim standard, your installed plugins, Vim distribution plugins):

  1. compiler/mycompiler.vim
  2. after/compiler/mycompiler.vim

Remark: You can learn more about in which order the scripts are executed using the :scriptname command.

8
  • Thanks. But I think it is more about what vim is looking for and less about vim loads and runs it. I am interested in the workings of vim once it finds such plugins
    – noobman
    Commented May 6, 2022 at 14:02
  • The chapter 14 title is somehow misleading. If you read it you will find information about in which orders the scripts are loaded (run) and it gave to me a good understanding about vim handle the plugin (sorry for pushing you to give it another try :-|) Commented May 6, 2022 at 14:17
  • Ah yes. I gave it a proper read this time. It does contain information along the lines of how things are and what the entire plugin model might look like. Certainly a start. I will wait if something more specialized is referred else I will accept this answer. Thanks!
    – noobman
    Commented May 6, 2022 at 14:29
  • 1
    @noobman it seems to me you are more interested in the implementation details (i.e., C code) that parses and executes vimscript? There are a couple of special vimscript files that actually implement the filetype mechanism, among other things (see the files in :Explore $VIMRUNTIME, for example filetype.vim and ftplugin.vim). For the C code, perhaps you could edit the question to clarify that's the kind of implementation you are interested in?
    – D. Ben Knoble
    Commented May 6, 2022 at 20:11
  • 2
    @noobman I think it's important to realize there is nothing "special" about plugins: everything you can do in a plugin you can do in your vimrc file. From Vim's perspective, there is essentially no difference between "plugin code" and "normal VimScript code". Using :source ~/.vim/myplugin/myplugin.vim has the same effect as "using a plugin". Vim's "plugin system" is little more than a set of filepaths to make organizing and distributing bits of VimScript easier. Commented May 7, 2022 at 1:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.