junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
33.7k stars 1.9k forks source link

On demand loading with user defined commands? #1261

Closed shmerl closed 5 months ago

shmerl commented 6 months ago

I'm trying to load a few plugins based on a custom command. So I defined something like this:

" Command to trigger loading of debugging related plugins on-demand
command LoadDebug echo 'Loading debug plugins'
...

And then in the vim-plug section, I was doing this:

" DAP debugging support
Plug 'mfussenegger/nvim-dap', { 'on': 'LoadDebug' }
Plug 'rcarriga/nvim-dap-ui', { 'on': 'LoadDebug' }

But it doesn't work. It does work with some other commands defined by plugins themselves. Is there a way to make it work or may be I'm missing something?

wookayin commented 6 months ago

vim-plug currently can't source lua plugins when lazy-loaded. #1157

junegunn commented 5 months ago

1157 is now merged. Thanks @wookayin


Plug 'mfussenegger/nvim-dap', { 'on': 'LoadDebug' }

That's not how you do it. When you write { 'on': 'LoadDebug' }, vim-plug defines a proxy command in that name which loads the plugin and executes the command from the loaded plugin.

Instead, you can pass an empty array as on so that the plugins are not loaded, and call plug#load from your command to load those plugins later.

Plug 'mfussenegger/nvim-dap', { 'on': [] }
Plug 'rcarriga/nvim-dap-ui', { 'on': [] }

command! LoadDebug call plug#load('nvim-dap', 'nvim-dap-ui')