I'm using vim-plug for managing plugins, primarily for its lazy-loading capabilities. This lets me do:

Plug 'Valloric/YouCompleteMe', { 'do': 'python2 ./install.py --clang-completer --gocode-completer --tern-completer', …}

I don't have YCM in all systems where I do have my .vim present and updated, and sometimes I'm not interested in having it present or installed - Supertab suffices for my needs in these cases, and installing YCM takes too much time, and YCM itself might be too heavyweight.

Now, I can skip the build step, since it is a shell command and I can probably do something like 'do': '[[ -z $INSTALL_YCM ]] && python2 …'. Can I get vim-plug to skip cloning the YCM plugin altogether? It has a bunch of submodules (and submodules within submodules … it's turtles all the way down), and downloading all that would just be a waste of time and bandwidth.

YCM is just an example. As I add more plugins (I have 17 now, and as I understand, some users have twice as many), I would be interested in skipping plugins on systems where they have no use at all. So, don't focus on YCM.

  • 4
    Doesn't wrapping the Plug statement inside an if block work? I use it successfully with Vundle to decide on a certain plugin for neovim and vim.
    – tokoyami
    Mar 23, 2016 at 16:10
  • 2
    You can use if some_condition in vim-plug blocks without problem.
    – VanLaser
    Mar 23, 2016 at 16:16
  • 1
    @VanLaser so what parts of Vimscript do I need to be careful of in the vim-plug block? I don't think a, b is regular Vim syntax for anything in command arguments, so just seeing the use of a , made me wonder at first - and then the autocmd bit made me more nervous.
    – muru
    Mar 23, 2016 at 16:20
  • 3
    I mean something like what you see in this picture: vi.stackexchange.com/a/4184/1800, but instead of using executable, you can check some other Vim or environmental variable (such as the host name).
    – VanLaser
    Mar 23, 2016 at 16:22
  • 2
    @VanLaser It is rather straightforward, then. Thanks!
    – muru
    Mar 23, 2016 at 16:26

2 Answers 2


From the FAQ (prettier formatting there):

Conditional activation

Use plain "if" statement to conditionally activate plugins:

if has('mac')
  Plug 'junegunn/vim-xmark'

The caveat is that when the condition is not met, PlugClean will try to remove the plugin. This can be problematic if you share the same configuration across terminal Vim, GVim, and Neovim.

" When started with plain Vim, the plugin is not registered
" and PlugClean will try to remove it
if has('nvim')
  Plug 'benekastah/neomake'

Alternatively, you can pass an empty on or for option so that the plugin is registered but not loaded by default depending on the condition.

Plug 'benekastah/neomake', has('nvim') ? {} : { 'on': [] }

A helper function can improve the readability.

function! Cond(cond, ...)
  let opts = get(a:000, 0, {})
  return a:cond ? opts : extend(opts, { 'on': [], 'for': [] })

" Looks better
Plug 'benekastah/neomake', Cond(has('nvim'))

" With other options
Plug 'benekastah/neomake', Cond(has('nvim'), { 'on': 'Neomake' })

As noted in the comments, you can use Vimscript within the vim-plug block, so I ended up checking for particular commands to control installation of plugins. For example, I rarely have cmake installed, I usually install it for YCM. So a executable('cmake') check is good enough for that. Now, my vim-plug block has one section for common plugins, and a set of checks for those which are useful in specific cases:

call plug#begin()
" Common plugins
Plug 'vim-scripts/diffchar.vim'
Plug 'scrooloose/nerdtree'
Plug 'ervandew/supertab'
Plug 'scrooloose/syntastic'
Plug 'tpope/vim-surround'
Plug 'bling/vim-airline'
Plug 'tpope/vim-fugitive'
Plug 'tomasr/molokai'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'gabrielelana/vim-markdown', {'for': 'markdown'}
Plug 'majutsushi/tagbar', {'for': ['cpp', 'c', 'go', 'sh', 'js']}
Plug 'godlygeek/tabular'

if executable('cmake')
    " YCM command lifted from vim-plug readme
    Plug 'Valloric/YouCompleteMe', { 'do': YCMInstallCmd(), 'for': ['cpp', 'c', 'go', 'sh', 'js', 'vim'] }
    autocmd! User YouCompleteMe if !has('vim_starting') | call youcompleteme#Enable() | endif
if executable('go')
    Plug 'fatih/vim-go', {'for': 'go'}
if executable('latex')
    Plug 'lervag/vimtex', {'for': 'tex'}
if executable('ghc')
    Plug 'dag/vim2hs', {'for': 'hs'}
if executable('man')
    Plug 'murukeshm/vim-manpager'
if executable('dpkg')
    Plug 'vim-scripts/deb.vim'
if executable('logrotate')
    Plug 'moon-musick/vim-logrotate'
call plug#end()

Your Answer

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

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