Optional plugins added with :packadd! foo
are not sourced in the prescribed order.
Create the following directory structure:
pack/brands/start/adidas/plugin/adidas.vim
pack/brands/start/nike/plugin/nike.vim
pack/brands/start/puma/plugin/puma.vim
Start Vim and do: :filter brands scriptnames
:
9: ~/.vim/pack/brands/start/adidas/plugin/adidas.vim
10: ~/.vim/pack/brands/start/nike/plugin/nike.vim
11: ~/.vim/pack/brands/start/puma/plugin/puma.vim
Plugins are sourced in filesystem order, which seems intuitive enough.
Rename pack/brands/start
to pack/brands/opt
:
pack/brands/opt/adidas/plugin/adidas.vim
pack/brands/opt/nike/plugin/nike.vim
pack/brands/opt/puma/plugin/puma.vim
Add the following at the top of $MYVIMRC
:
filetype on
packadd! adidas
packadd! nike
packadd! puma
finish
Start Vim and do :filter brands scriptnames
:
9: ~/.vim/pack/brands/start/puma/plugin/puma.vim
10: ~/.vim/pack/brands/start/nike/plugin/nike.vim
11: ~/.vim/pack/brands/start/adidas/plugin/adidas.vim
Plugins are sourced in reverse :packadd
order, which is not documented and rather counter-intuitive.
Sourcing order should be the same as :packadd
order:
9: ~/.vim/pack/brands/start/adidas/plugin/adidas.vim
10: ~/.vim/pack/brands/start/nike/plugin/nike.vim
11: ~/.vim/pack/brands/start/puma/plugin/puma.vim
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
This to be expected, ":packadd!" does not load the pack, that is postponed. Thus the order can change. And the implementation prepends the directory to 'runtimepath', thus the order is reversed.
I'll add a note in the documentation. In general the order doesn't matter anyway.
And the implementation prepends the directory to 'runtimepath', thus the order is reversed.
The directories are added to &rtp
in the same order in both cases, though:
[…]
/Users/romainl/.vim/pack/brands/start/puma,
/Users/romainl/.vim/pack/brands/start/nike,
/Users/romainl/.vim/pack/brands/start/adidas,
[…]
and:
[…]
/Users/romainl/.vim/pack/brands/opt/puma,
/Users/romainl/.vim/pack/brands/opt/nike,
/Users/romainl/.vim/pack/brands/opt/adidas,
[…]
and yet the plugins are sourced in different orders:
&rtp
when using opt
and :packadd!
,&rtp
when using start
.which I can't explain.
In general the order doesn't matter anyway.
"In general", maybe, but apparently not in some specific cases involving popular plugins.
In the first case the packs are added when found, and the directory is added in 'runtimepath' in that order.
When using packadd! the directories are added to 'runtimepath' and only later the packs are added, when finding plugins in 'runtimepath'.
The problem with this is that, when adding those directories manually to &rtp
, the plugins are sourced in the order they were added: you add adidas
, then nike
, then puma
and they are sourced in that order.
If I can expect the outcome for the following snippet:
let rtp1 = &rtp->split(',')->filter({ idx, val -> val !~ "after$" })
let rtp2 = &rtp->split(',')->filter({ idx, val -> val =~ "after$" })
call add(rtp1, '/Users/romainl/.vim/pack/brands/foo/nike')
call add(rtp1, '/Users/romainl/.vim/pack/brands/foo/adidas')
call add(rtp1, '/Users/romainl/.vim/pack/brands/foo/puma')
let &rtp = (rtp1 + rtp2)->join(',')
to be that the plugins are sourced in the specified order, why can't I expect the same outcome for the following snippet?
:packadd! nike
:packadd! adidas
:packadd! puma