vim-plug icon indicating copy to clipboard operation
vim-plug copied to clipboard

Deferred loading on autocmd (#event[#pattern])

Open junegunn opened this issue 7 years ago • 9 comments

Does not mean that I'm positive on this. I'm just posting the patch as it was trivial to implement the idea.

Plug 'SirVer/ultisnips',  { 'on': '#InsertEnter' }
Plug 'junegunn/goyo.vim', { 'on': ['Goyo', '#BufEnter#README,BUILD,CHANGELOG'] }

(See :help exists() for #event#pattern syntax)

junegunn avatar Oct 29 '16 09:10 junegunn

Since which version is the #event#pattern syntax supported? Just asking because you don't seems to have a minimum version of vim for vim-plug and I wouldn't want you to break some users :)

vheon avatar Oct 31 '16 15:10 vheon

It has been quite some time.

https://github.com/vim/vim/commit/f4cd3e8074641af68bf2b6a8579c3da58f0ac013 https://github.com/vim/vim/commit/a9b1e74b5d1d59c0a071ccacfe9aaaca9b4a5cca

The code in this PR only uses exists('##EventName'). #event#pattern syntax was chosen not to introduce a new, arbitrary syntax, but it's not directly used. The code splits the string.

junegunn avatar Oct 31 '16 15:10 junegunn

Thanks for digging that up! 😉 As usual I hope that there is a real use for this other than YCM (I know you get a lots of requests from it).

vheon avatar Oct 31 '16 22:10 vheon

I think this would be good to have.

But for my use case I would need to be able to a) call a custom function afterwards (deoplete#enable()), and b) would like to limit it to a filetypes also (i.e. #InsertEnter, but only for python filetypes).

blueyed avatar Dec 01 '16 21:12 blueyed

call a custom function afterwards

That is also useful for lazy-loading Unite, so that you can customize it using call unite#custom#source(…) etc.

blueyed avatar Dec 06 '16 13:12 blueyed

@blueyed

call a custom function afterwards

vim-plug currently supports that via User autocmd

" Code to execute when the plugin is lazily loaded on demand
Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
autocmd! User goyo.vim echom 'Goyo is now loaded!'

Have you tried it?

b) would like to limit it to a filetypes also (i.e. #InsertEnter, but only for python filetypes).

Hmm, I certainly wouldn't want to go that far. In my opinion, custom autocmd is the answer to such complex use cases.

junegunn avatar Dec 08 '16 04:12 junegunn

@junegunn

vim-plug currently supports that via User autocmd

Oh, I missed that, sorry. That is nice. But I wonder if the autocommand name should not have something like a plug_loaded_ prefix?! Otherwise it could conflict/overlap with a plugin's own custom User autocommand?!

Thanks!

blueyed avatar Dec 10 '16 14:12 blueyed

I think this is a neat little feature, I'm currently using:

Plug 'vim-syntastic/syntastic', { 'on': [] }
"Delay syntatic load until we aren't doing anything
augroup LazySyntatic
  autocmd!
  autocmd CursorHold * :call plug#load('syntastic')
  autocmd CursorHold * :autocmd! LazySyntatic
augroup END

to delay the loading of syntastic. With deferred autoload that could be hidden away with:

Plug 'vim-syntastic/syntastic', { 'on': '#CursorHold' }

jbro avatar Mar 09 '17 07:03 jbro

So, can plug support event now? I'm using SpaceVim which using 'dein' as their default plugin manager and I want to switch to plug , which is my favorite vim plugin manager. But I need this feature because so many plugin in SpaceVim need this. So, anyone can help with this feature? @junegunn @blueyed

SwenChan avatar Aug 28 '19 04:08 SwenChan