mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-23 20:45:31 -07:00
Conditional activation
parent
28ffe374c6
commit
d0c67ec987
61
faq.md
61
faq.md
@ -14,20 +14,45 @@ endif
|
||||
|
||||
(If you're behind an HTTP proxy, you may need to add `--insecure` option to the curl command. In that case, you also need to set `$GIT_SSL_NO_VERIFY` to true.)
|
||||
|
||||
### Loading plugins manually
|
||||
### Conditional activation
|
||||
|
||||
With `on` and `for` options, vim-plug allows you to defer loading of plugins. But if you want a plugin to be loaded on an event that is not supported by vim-plug, you can set `on` or `for` option to an empty list, and use `plug#load(names...)` function later to load the plugin manually. The following example will load [ultisnips](https://github.com/SirVer/ultisnips) and [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) first time you enter insert mode.
|
||||
Use plain "if" statement to conditionally activate plugins:
|
||||
|
||||
```vim
|
||||
" Load on nothing
|
||||
Plug 'SirVer/ultisnips', { 'on': [] }
|
||||
Plug 'Valloric/YouCompleteMe', { 'on': [] }
|
||||
if has('mac')
|
||||
Plug 'junegunn/vim-xmark'
|
||||
endif
|
||||
```
|
||||
|
||||
augroup load_us_ycm
|
||||
autocmd!
|
||||
autocmd InsertEnter * call plug#load('ultisnips', 'YouCompleteMe')
|
||||
\| call youcompleteme#Enable() | autocmd! load_us_ycm
|
||||
augroup END
|
||||
The caveat is that when the condition is not met, `PlugClean` will try to remove the plugin. This can be problematic if you shar the same configuration across terminal Vim, GVim, and Neovim.
|
||||
|
||||
```vim
|
||||
" When started with plain Vim, the plugin is not registered
|
||||
" and PlugClean will try to remove it
|
||||
if has('nvim')
|
||||
Plug 'benekastah/neomake'
|
||||
endif
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```vim
|
||||
Plug 'benekastah/neomake', has('nvim') ? {} : { 'on': [] }
|
||||
```
|
||||
|
||||
A helper function can improve the readability.
|
||||
|
||||
```vim
|
||||
function! Cond(cond, ...)
|
||||
let opts = get(a:000, 0, {})
|
||||
return a:cond ? opts : extend(opts, { 'on': [] })
|
||||
endfunction
|
||||
|
||||
" Looks better
|
||||
Plug 'benekastah/neomake', Cond(has('nvim'))
|
||||
|
||||
" With other options
|
||||
Plug 'benekastah/neomake', Cond(has('nvim'), { 'on': 'Neomake' })
|
||||
```
|
||||
|
||||
### Gist as plugin
|
||||
@ -102,6 +127,22 @@ call plug#begin('~/.vim/bundle')
|
||||
call plug#begin('~/vimfiles/bundle')
|
||||
```
|
||||
|
||||
### Loading plugins manually
|
||||
|
||||
With `on` and `for` options, vim-plug allows you to defer loading of plugins. But if you want a plugin to be loaded on an event that is not supported by vim-plug, you can set `on` or `for` option to an empty list, and use `plug#load(names...)` function later to load the plugin manually. The following example will load [ultisnips](https://github.com/SirVer/ultisnips) and [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) first time you enter insert mode.
|
||||
|
||||
```vim
|
||||
" Load on nothing
|
||||
Plug 'SirVer/ultisnips', { 'on': [] }
|
||||
Plug 'Valloric/YouCompleteMe', { 'on': [] }
|
||||
|
||||
augroup load_us_ycm
|
||||
autocmd!
|
||||
autocmd InsertEnter * call plug#load('ultisnips', 'YouCompleteMe')
|
||||
\| call youcompleteme#Enable() | autocmd! load_us_ycm
|
||||
augroup END
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
### Does vim-plug generate help tags for my plugins?
|
||||
|
Loading…
Reference in New Issue
Block a user