mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-24 04:56:33 -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.)
|
(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
|
```vim
|
||||||
" Load on nothing
|
if has('mac')
|
||||||
Plug 'SirVer/ultisnips', { 'on': [] }
|
Plug 'junegunn/vim-xmark'
|
||||||
Plug 'Valloric/YouCompleteMe', { 'on': [] }
|
endif
|
||||||
|
```
|
||||||
|
|
||||||
augroup load_us_ycm
|
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.
|
||||||
autocmd!
|
|
||||||
autocmd InsertEnter * call plug#load('ultisnips', 'YouCompleteMe')
|
```vim
|
||||||
\| call youcompleteme#Enable() | autocmd! load_us_ycm
|
" When started with plain Vim, the plugin is not registered
|
||||||
augroup END
|
" 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
|
### Gist as plugin
|
||||||
@ -102,6 +127,22 @@ call plug#begin('~/.vim/bundle')
|
|||||||
call plug#begin('~/vimfiles/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
|
## FAQ
|
||||||
|
|
||||||
### Does vim-plug generate help tags for my plugins?
|
### Does vim-plug generate help tags for my plugins?
|
||||||
|
Loading…
Reference in New Issue
Block a user