3

Currently, I am trying to create a ~/.vimrc file that I will be able to integrate into any environment and get all my configs with minimum user interference.

In order to simplify my vim configuration. I decided to install my plugins into the ~/.vim/plugged directory and the colorschemes into another directory ~/.vim/colors.

Supposedly, I would run 2 commands in vim to install the plugins :source % :PlugInstall and then extract the colorscheme *(.vim)* from the ~/.vim/color/gruvbox/color and ~/.vim/color/vim-monokai/color directories in order to make the config more versatile.

Briefly talking, the problem is that the plugins stop working - eg: :NERDTreeToggle would result in

:NERDTreeToggle is not an edditor command

if there are two call plug#begin/end statements in the file but the colorschemes get installed as expected.

call plug#begin('~/.vim/plugged')
Plug 'mbbill/undotree'
Plug 'ycm-core/YouCompleteMe'
Plug 'preservim/nerdtree'
Plug 'lyuts/vim-rtags'
Plug 'vim-utils/vim-man'
" Git Integration:
Plug 'mhinz/vim-signify'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'junegunn/gv.vim'
call plug#end()

call plug#begin('~/.vim/colors')
" Colorscheme:
Plug 'morhetz/gruvbox'
Plug 'sickill/vim-monokai'
call plug#end()

Although I was able to fix the problem simply by putting all repos into one call plug#begin/end block as indicated below, I am still curious if there exists a different solution to the problem.

call plug#begin('~/.vim/plugged')
Plug 'mbbill/undotree'
Plug 'ycm-core/YouCompleteMe'
Plug 'preservim/nerdtree'
Plug 'lyuts/vim-rtags'
Plug 'vim-utils/vim-man'
" Git Integration:
Plug 'mhinz/vim-signify'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'junegunn/gv.vim'
" Colorscheme:
Plug 'morhetz/gruvbox'
Plug 'sickill/vim-monokai'
call plug#end()

PS: I am using vim-plug as my plugin manager

2
  • Welcome to Vi and Vim! I wonder if the second call to plug#begin is what screws things up? You might have some luck asking on their issue tracker; the maintainers are likely to know what's going on here.
    – D. Ben Knoble
    Jul 19, 2020 at 1:37
  • I'm not sure I understand why you want to use a different directory for your colorscheme: They still are pluggins but they already use a color directory to keep things clean and as you saw trying to put them in a different directory doesn't really makes things simpler. Maybe what you want to do is having a separate vimrc to have different configurations, in this case maybe this question could be useful?
    – statox
    Jul 19, 2020 at 12:00

1 Answer 1

4

So your question has already been asked in vim-plug's issue tracker, see #905.

@raindev said this (I changed the link to the code to not use master in case the code changes in the future):

I don't think that will work currently as each call to plug#begin resets Plug configuration (and not appends to it): https://github.com/junegunn/vim-plug/blob/c31903639623c5be2431a/plug.vim#L166-L169

I've run into this issue trying to have multiple plug sections: only plugins from the last one will be included.

Also @janlazo (who is one of the current maintainers) said that changing that would require a big refactor and thus I think there are few chances that the feature will be one day added to vim-plug.


Now what would be interesting is to understand why you think having your colorscheme in a different repository would simplify your configuration:

  • As you already noticed it doesn't integrate well with vim-plug. Note that it could work if you used the build-in package manager (see What is the Vim8 package feature and how should I use it? ) but that would require quite a change in your configuration
  • This is not a standard practice (have a look at a few dotfiles repos on Github and you'll see it's not) thus making your configuration less consistent with the ecosystem.
  • It doesn't add much value since the colorscheme plugins already have a color directory which integrates well with Vim built-in mechanisms.

So my advise would be to avoid doing what you are trying to do. However you could still want to have some logic in your vimrc to source plugins depending on the machine you are using.

In this question I asked, @VanLaser suggests a simple way to source a file containing some Plug '.../...' directives only if the file exists. And on another vim-plug issue @janlazo suggests to add a function in the plugin section which would source some plugins.

Maybe you can get some inspiration from these ideas to add the logic you want in your plugins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.