Skip to main content
added 7 characters in body
Source Link
Matt
  • 22.7k
  • 1
  • 17
  • 27

As I don't know where to find the "written" rules, I digged into the source code instead. Also note that there are both Vim and Neovim, but it looks that they still share almost the same code in this regard, so the following applies to both.

Also, let me remind that there is rtp-order and load-order, and they are different, as it'sit becomes clear from comparing the output of :set rtp? and :scriptnames.

So Vim does the following:

  1. Execute :h --cmd if any
  2. Source startup scripts (like .vimrc and stuff). Note that .vimrc may use :packloadall and such to force early plugins load
  3. Save a copy of &rtp
  4. Add plugins directories to &rtp (needed to make sure all autoload's are found).
  5. Load standard plugins (i.e. plugin/**/*.vim from saved &rtp, except for after)
  6. Load user plugins (i.e. pack/*/start/* from &packpath!)
  7. Source after-plugins from new (current) &rtp

Now you ask about step (4) explicitly. On this step Vim finds every pack/*/start/* from &packpath and, if it's not yet in &rtp, adds it. The relevant code is in function named add_pack_dir_to_rtp() found in src/scriptfile.c (Vim) or src/ex_cmds2.c (Neovim).

As far as I understand, it simply takes the path prefix (before pack/... part) and tries to find the first match (like strncmp() with the length of the prefix) in the current &rtp and put it just after it. Hence all the user plugins paths normally go after ~/.vim but in reverse order (compared to their natural find-and-load-order). If no match was found they are added tothen the end ofitem is appended to &rtp (with respect to after).

As I don't know where to find the "written" rules, I digged into the source code instead. Also note that there are both Vim and Neovim, but it looks that they still share almost the same code in this regard, so the following applies to both.

Also, let me remind that there is rtp-order and load-order, and they are different, as it's clear from comparing the output of :set rtp? and :scriptnames

So Vim does the following:

  1. Execute :h --cmd if any
  2. Source startup scripts (like .vimrc and stuff). Note that .vimrc may use :packloadall and such to force early plugins load
  3. Save a copy of &rtp
  4. Add plugins directories to &rtp (needed to make sure all autoload's are found).
  5. Load standard plugins (i.e. plugin/**/*.vim from saved &rtp, except for after)
  6. Load user plugins (i.e. pack/*/start/* from &packpath!)
  7. Source after-plugins from new (current) &rtp

Now you ask about step (4) explicitly. On this step Vim finds every pack/*/start/* from &packpath and, if it's not yet in &rtp, adds it. The relevant code is in function named add_pack_dir_to_rtp() found in src/scriptfile.c (Vim) or src/ex_cmds2.c (Neovim).

As far as I understand, it simply takes the path prefix (before pack/... part) and tries to find the first match (like strncmp() with the length of the prefix) in the current &rtp and put it just after it. Hence all the user plugins paths normally go after ~/.vim but in reverse order (compared to their natural find-and-load-order). If no match was found they are added to the end of &rtp (with respect to after).

As I don't know where to find the "written" rules, I digged into the source code instead. Also note that there are both Vim and Neovim, but it looks that they still share almost the same code in this regard, so the following applies to both.

Also, let me remind that there is rtp-order and load-order, and they are different, as it becomes clear from comparing the output of :set rtp? and :scriptnames.

So Vim does the following:

  1. Execute :h --cmd if any
  2. Source startup scripts (like .vimrc and stuff). Note that .vimrc may use :packloadall and such to force early plugins load
  3. Save a copy of &rtp
  4. Add plugins directories to &rtp (needed to make sure all autoload's are found).
  5. Load standard plugins (i.e. plugin/**/*.vim from saved &rtp, except for after)
  6. Load user plugins (i.e. pack/*/start/* from &packpath!)
  7. Source after-plugins from new (current) &rtp

Now you ask about step (4) explicitly. On this step Vim finds every pack/*/start/* from &packpath and, if it's not yet in &rtp, adds it. The relevant code is in function named add_pack_dir_to_rtp() found in src/scriptfile.c (Vim) or src/ex_cmds2.c (Neovim).

As far as I understand, it simply takes the path prefix (before pack/... part) and tries to find the first match (like strncmp() with the length of the prefix) in the current &rtp and put it just after it. Hence all the user plugins paths normally go after ~/.vim but in reverse order (compared to their natural find-and-load-order). If no match was found then the item is appended to &rtp (with respect to after).

Source Link
Matt
  • 22.7k
  • 1
  • 17
  • 27

As I don't know where to find the "written" rules, I digged into the source code instead. Also note that there are both Vim and Neovim, but it looks that they still share almost the same code in this regard, so the following applies to both.

Also, let me remind that there is rtp-order and load-order, and they are different, as it's clear from comparing the output of :set rtp? and :scriptnames

So Vim does the following:

  1. Execute :h --cmd if any
  2. Source startup scripts (like .vimrc and stuff). Note that .vimrc may use :packloadall and such to force early plugins load
  3. Save a copy of &rtp
  4. Add plugins directories to &rtp (needed to make sure all autoload's are found).
  5. Load standard plugins (i.e. plugin/**/*.vim from saved &rtp, except for after)
  6. Load user plugins (i.e. pack/*/start/* from &packpath!)
  7. Source after-plugins from new (current) &rtp

Now you ask about step (4) explicitly. On this step Vim finds every pack/*/start/* from &packpath and, if it's not yet in &rtp, adds it. The relevant code is in function named add_pack_dir_to_rtp() found in src/scriptfile.c (Vim) or src/ex_cmds2.c (Neovim).

As far as I understand, it simply takes the path prefix (before pack/... part) and tries to find the first match (like strncmp() with the length of the prefix) in the current &rtp and put it just after it. Hence all the user plugins paths normally go after ~/.vim but in reverse order (compared to their natural find-and-load-order). If no match was found they are added to the end of &rtp (with respect to after).