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

Any way to load the contents of ".vim/plugin" before the contents of ".vim/plugged"?

Open dresb opened this issue 3 years ago • 2 comments

I like to use multiple configuration files split up by category inside the '.vim/plugin' and '.vim/after/plugin' folders depending on what aspect of the editor they modify (interface, rendering, theme, functions, etc.) I always assumed the contents of the "plugin" folder were sourced before the extensions and the "after" folder was sourced after, but turns out I was wrong. Judging by the output of 'vim --startuptime' I can see that some extension files are sourced before the contents of '.vim/plugin' which results in errors like "vim-polyglot: g:polyglot_disabled should be defined before loading vim-polyglot".

Right now I'm working around it by moving the files from 'plugin' to a different folder and manually sourcing them on my vimrc before executing plug. Is there a clean way to ensure the contents of '.vim/plugin' are sourced before loading the extensions?


  • Type:
    • [ ] Bug
    • [ ] Enhancement
    • [ ] Feature Request
    • [x] Question
  • OS:
    • [ ] All/Other
    • [x] Linux
    • [ ] OS X
    • [ ] Windows
  • Vim:
    • [x] Terminal Vim
    • [x] GVim
    • [ ] Neovim

dresb avatar Oct 27 '21 13:10 dresb

I like to use multiple configuration files split up by category inside the '.vim/plugin' and '.vim/after/plugin' folders depending on what aspect of the editor they modify (interface, rendering, theme, functions, etc.) I always assumed the contents of the "plugin" folder were sourced before the extensions and the "after" folder was sourced after, but turns out I was wrong. Judging by the output of 'vim --startuptime' I can see that some extension files are sourced before the contents of '.vim/plugin' which results in errors like "vim-polyglot: g:polyglot_disabled should be defined before loading vim-polyglot".

Right now I'm working around it by moving the files from 'plugin' to a different folder and manually sourcing them on my vimrc before executing plug. Is there a clean way to ensure the contents of '.vim/plugin' are sourced before loading the extensions?

* Type:
  
  * [ ]  Bug
  * [ ]  Enhancement
  * [ ]  Feature Request
  * [x]  Question

* OS:
  
  * [ ]  All/Other
  * [x]  Linux
  * [ ]  OS X
  * [ ]  Windows

* Vim:
  
  * [x]  Terminal Vim
  * [x]  GVim
  * [ ]  Neovim

I don't know whether you can understand Chinese. There is a sites about vim lazy load. https://blog.csdn.net/weixin_34204722/article/details/88669957 If you can't understand the Chinese. Maybe you can try the coc.nvim. A very good plugin for Vim. It supports the lazy load for itselt. But we can use it and vim-plug to delay loading other some plugins. Like the following code:

" coc setting " After 333ms, call the coc.nvim,delay the coc startup,vim-plug lazy load if has("nvim-0.5.0") || has("patch-8.1.1564") let g:coc_start_at_startup = 0 function! CocTimerStart(timer) exec "CocStart" silent call plug#load('gen_tags.vim') silent call plug#load('nerdcommenter') silent call plug#load('LeaderF') silent call plug#load('LeaderF-marks') silent call plug#load('asyncrun.vim') if &filetype=='markdown' silent call plug#load('vim-markdown-toc') silent call plug#load('vim-markdown') endif endfunction call timer_start(333,'CocTimerStart',{'repeat':1}) endif

And you should know about that not all plugins support lazy load. You have to test them if you want to delay loading them.

0BananaBig0 avatar Nov 09 '21 02:11 0BananaBig0

I like to use multiple configuration files split up by category inside the '.vim/plugin' and '.vim/after/plugin' folders depending on what aspect of the editor they modify (interface, rendering, theme, functions, etc.) I always assumed the contents of the "plugin" folder were sourced before the extensions and the "after" folder was sourced after, but turns out I was wrong. Judging by the output of 'vim --startuptime' I can see that some extension files are sourced before the contents of '.vim/plugin' which results in errors like "vim-polyglot: g:polyglot_disabled should be defined before loading vim-polyglot".

Right now I'm working around it by moving the files from 'plugin' to a different folder and manually sourcing them on my vimrc before executing plug. Is there a clean way to ensure the contents of '.vim/plugin' are sourced before loading the extensions?

* Type:
  
  * [ ]  Bug
  * [ ]  Enhancement
  * [ ]  Feature Request
  * [x]  Question

* OS:
  
  * [ ]  All/Other
  * [x]  Linux
  * [ ]  OS X
  * [ ]  Windows

* Vim:
  
  * [x]  Terminal Vim
  * [x]  GVim
  * [ ]  Neovim

https://github.com/Banana-Two/configuration_file/blob/master/.vimrc This is my .vimrc.

0BananaBig0 avatar Nov 09 '21 02:11 0BananaBig0

I'm running into the same issue. I get the same "vim-polyglot: g:polyglot_disabled should be defined before loading vim-polyglot", but that's not the only case where this is an issue.

Another example, this time with ale

ALE's own completion implementation can be enabled by setting
|g:ale_completion_enabled| to `1`. This setting must be set to `1` before ALE
is loaded.

If .vim/plugged/ale is loaded before .vim/plugin/ale.vim, then a user who set ale_completion_enabled=1 will silently have ale completion fail to work.

I think I can work around this by adding runtime! plugin/*.vim just above my call plug#begin()line in my vimrc file, but it does end up loading the plugin config files twice. Also there might be ramifications to the workaround I'm not thinking about.

austinmcconnell avatar Mar 26 '24 15:03 austinmcconnell

plugin directories are loaded in the order specified in &rtp, and you'll see that vim-plug puts ~/.vim at the front, so the files in ~/.vim/plugin are loaded before any other plugins.

The exception are ftdetect scripts from plugins. They are loaded on filetype plugin on which is called by plug#end(). It looks like the check of vim-polyglot is done via an ftdetect script (see :scriptnames), so in this case, you have to put the configuration before plug#end().

call plug#begin()
Plug 'sheerun/vim-polyglot'
  let g:polyglot_disabled = []

call plug#end()

For g:ale_completion_enabled, I have no issue putting it in a script in ~/.vim/plugin directory.

junegunn avatar Mar 28 '24 03:03 junegunn