mirror of
https://github.com/junegunn/vim-plug.git
synced 2025-12-24 09:31:25 +08:00
Load-on-demand with on option
This commit is contained in:
37
plug.vim
37
plug.vim
@@ -13,8 +13,9 @@
|
||||
"
|
||||
" Plug 'junegunn/seoul256.vim'
|
||||
" Plug 'junegunn/vim-easy-align'
|
||||
" Plug 'junegunn/goyo.vim', { 'on': 'Goyo' }
|
||||
" " Plug 'user/repo1', 'branch_or_tag'
|
||||
" " Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'devel' }
|
||||
" " Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'branch_or_tag' }
|
||||
" " ...
|
||||
"
|
||||
" call plug#end()
|
||||
@@ -110,10 +111,17 @@ function! plug#end()
|
||||
|
||||
filetype off
|
||||
for plug in values(g:plugs)
|
||||
let rtp = s:rtp(plug)
|
||||
execute "set rtp^=".rtp
|
||||
if isdirectory(rtp.'after')
|
||||
execute "set rtp+=".rtp.'after'
|
||||
if has_key(plug, 'on')
|
||||
let commands = type(plug.on) == 1 ? [plug.on] : plug.on
|
||||
for cmd in commands
|
||||
if !exists(':'.cmd)
|
||||
execute printf(
|
||||
\ "command! -nargs=* -bang %s call s:lod(%s, '<bang>', <q-args>, %s)",
|
||||
\ cmd, string(cmd), string(plug))
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call s:add_rtp(s:rtp(plug))
|
||||
endif
|
||||
endfor
|
||||
filetype plugin indent on
|
||||
@@ -128,6 +136,25 @@ function! s:rtp(spec)
|
||||
return rtp
|
||||
endfunction
|
||||
|
||||
function! s:add_rtp(rtp)
|
||||
execute "set rtp^=".a:rtp
|
||||
if isdirectory(a:rtp.'after')
|
||||
execute "set rtp+=".a:rtp.'after'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:lod(cmd, bang, args, plug)
|
||||
execute 'delc '.a:cmd
|
||||
let rtp = s:rtp(a:plug)
|
||||
call s:add_rtp(rtp)
|
||||
for dir in ['plugin', 'after']
|
||||
for vim in split(globpath(rtp, dir.'/*.vim'), '\n')
|
||||
execute 'source '.vim
|
||||
endfor
|
||||
endfor
|
||||
execute printf("%s%s %s", a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
|
||||
function! s:add(...)
|
||||
let force = a:1
|
||||
let opts = { 'branch': 'master' }
|
||||
|
||||
Reference in New Issue
Block a user