mirror of
https://github.com/junegunn/vim-plug.git
synced 2025-12-08 01:44:44 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d477a1a01 | ||
|
|
288a4f72ce | ||
|
|
5168cd50db | ||
|
|
4d32762432 | ||
|
|
8dff1dae37 | ||
|
|
b5b687ad9a | ||
|
|
7e69a50890 | ||
|
|
476a613746 | ||
|
|
12b5dcb903 |
25
README.md
25
README.md
@@ -38,7 +38,8 @@ call plug#begin('~/.vim/plugged')
|
||||
|
||||
Plug 'junegunn/seoul256.vim'
|
||||
Plug 'junegunn/vim-easy-align'
|
||||
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
||||
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
||||
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
|
||||
" Plug 'user/repo1', 'branch_or_tag'
|
||||
" Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'devel' }
|
||||
" Plug 'git@github.com:junegunn/vim-github-dashboard.git'
|
||||
@@ -59,14 +60,14 @@ before the call.
|
||||
|
||||
### Commands
|
||||
|
||||
| Command | Description |
|
||||
| ---------------------- | ------------------------------------------------------------------ |
|
||||
| PlugInstall [#threads] | Install plugins |
|
||||
| PlugUpdate [#threads] | Install or update plugins |
|
||||
| PlugClean[!] | Remove unused directories (bang version will clean without prompt) |
|
||||
| PlugUpgrade | Upgrade vim-plug itself |
|
||||
| PlugStatus | Check the status of plugins |
|
||||
| PlugDiff | See the updated changes from the previous PlugUpdate |
|
||||
| Command | Description |
|
||||
| --------------------------------- | ------------------------------------------------------------------ |
|
||||
| PlugInstall [name ...] [#threads] | Install plugins |
|
||||
| PlugUpdate [name ...] [#threads] | Install or update plugins |
|
||||
| PlugClean[!] | Remove unused directories (bang version will clean without prompt) |
|
||||
| PlugUpgrade | Upgrade vim-plug itself |
|
||||
| PlugStatus | Check the status of plugins |
|
||||
| PlugDiff | See the updated changes from the previous PlugUpdate |
|
||||
|
||||
### Options for parallel installer
|
||||
|
||||
@@ -97,6 +98,12 @@ Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
||||
|
||||
" Multiple commands
|
||||
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }
|
||||
|
||||
" Loaded when clojure file is opened
|
||||
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
|
||||
|
||||
" On-demand loading on both conditions
|
||||
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' }
|
||||
```
|
||||
|
||||
### Dependency resolution
|
||||
|
||||
119
plug.vim
119
plug.vim
@@ -24,7 +24,7 @@
|
||||
" You can change the location of the plugins with plug#begin(path) call.
|
||||
"
|
||||
"
|
||||
" Copyright (c) 2013 Junegunn Choi
|
||||
" Copyright (c) 2014 Junegunn Choi
|
||||
"
|
||||
" MIT License
|
||||
"
|
||||
@@ -58,6 +58,7 @@ set cpo&vim
|
||||
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
|
||||
let s:plug_file = 'Plugfile'
|
||||
let s:plug_buf = -1
|
||||
let s:loaded = {}
|
||||
let s:is_win = has('win32') || has('win64')
|
||||
let s:me = expand('<sfile>:p')
|
||||
|
||||
@@ -91,9 +92,9 @@ function! plug#begin(...)
|
||||
" we want to keep track of the order plugins where registered.
|
||||
let g:plugs_order = []
|
||||
|
||||
command! -nargs=+ Plug call s:add(1, <args>)
|
||||
command! -nargs=* PlugInstall call s:install(<f-args>)
|
||||
command! -nargs=* PlugUpdate call s:update(<f-args>)
|
||||
command! -nargs=+ -bar Plug call s:add(1, <args>)
|
||||
command! -nargs=* -complete=customlist,s:names PlugInstall call s:install(<f-args>)
|
||||
command! -nargs=* -complete=customlist,s:names PlugUpdate call s:update(<f-args>)
|
||||
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
||||
command! -nargs=0 PlugUpgrade if s:upgrade() | execute "source ". s:me | endif
|
||||
command! -nargs=0 PlugStatus call s:status()
|
||||
@@ -102,6 +103,10 @@ function! plug#begin(...)
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:to_a(v)
|
||||
return type(a:v) == 3 ? a:v : [a:v]
|
||||
endfunction
|
||||
|
||||
function! plug#end()
|
||||
if !exists('g:plugs')
|
||||
echoerr 'Call plug#begin() first'
|
||||
@@ -112,15 +117,36 @@ function! plug#end()
|
||||
let keys = keys(s:extend(keys))
|
||||
endwhile
|
||||
|
||||
if exists('#PlugLOD')
|
||||
augroup PlugLOD
|
||||
autocmd!
|
||||
augroup END
|
||||
augroup! PlugLOD
|
||||
endif
|
||||
|
||||
filetype off
|
||||
if exists('#filetypeplugin') &&
|
||||
\ !empty(filter(values(g:plugs), 'has_key(v:val, "for")'))
|
||||
unlet! g:did_load_ftplugin
|
||||
augroup filetypeplugin
|
||||
autocmd!
|
||||
augroup END
|
||||
augroup! filetypeplugin
|
||||
endif
|
||||
|
||||
" we want to make sure the plugin directories are added to rtp in the same
|
||||
" order that they are registered with the Plug command. since the s:add_rtp
|
||||
" function uses ^= to add plugin directories to the front of the rtp, we
|
||||
" need to loop through the plugins in reverse
|
||||
for name in reverse(copy(g:plugs_order))
|
||||
let plug = g:plugs[name]
|
||||
if !has_key(plug, 'on') && !has_key(plug, 'for')
|
||||
call s:add_rtp(s:rtp(plug))
|
||||
continue
|
||||
endif
|
||||
|
||||
if has_key(plug, 'on')
|
||||
let commands = type(plug.on) == 1 ? [plug.on] : plug.on
|
||||
let commands = s:to_a(plug.on)
|
||||
for cmd in commands
|
||||
if cmd =~ '^<Plug>.\+'
|
||||
if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
|
||||
@@ -132,12 +158,20 @@ function! plug#end()
|
||||
endif
|
||||
elseif !exists(':'.cmd)
|
||||
execute printf(
|
||||
\ "command! -nargs=* -bang %s call s:lod_cmd(%s, '<bang>', <q-args>, %s)",
|
||||
\ "command! -nargs=* -range -bang %s call s:lod_cmd(%s, '<bang>', <line1>, <line2>, <q-args>, %s)",
|
||||
\ cmd, string(cmd), string(plug))
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call s:add_rtp(s:rtp(plug))
|
||||
endif
|
||||
|
||||
if has_key(plug, 'for')
|
||||
for vim in split(globpath(s:rtp(plug), 'ftdetect/**/*.vim'), '\n')
|
||||
execute 'source '.vim
|
||||
endfor
|
||||
augroup PlugLOD
|
||||
execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s)',
|
||||
\ join(s:to_a(plug.for), ','), string(name), string(plug))
|
||||
augroup END
|
||||
endif
|
||||
endfor
|
||||
filetype plugin indent on
|
||||
@@ -163,26 +197,34 @@ function! s:add_rtp(rtp)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:lod(plug)
|
||||
function! s:lod(plug, types)
|
||||
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')
|
||||
for dir in a:types
|
||||
for vim in split(globpath(rtp, dir.'/**/*.vim'), '\n')
|
||||
execute 'source '.vim
|
||||
endfor
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:lod_cmd(cmd, bang, args, plug)
|
||||
function! s:lod_ft(name, plug)
|
||||
if has_key(s:loaded, a:name)
|
||||
return
|
||||
endif
|
||||
call s:lod(a:plug, ['plugin', 'after'])
|
||||
let s:loaded[a:name] = 1
|
||||
endfunction
|
||||
|
||||
function! s:lod_cmd(cmd, bang, l1, l2, args, plug)
|
||||
execute 'delc '.a:cmd
|
||||
call s:lod(a:plug)
|
||||
execute printf("%s%s %s", a:cmd, a:bang, a:args)
|
||||
call s:lod(a:plug, ['plugin', 'ftdetect', 'after'])
|
||||
execute printf("%s%s%s %s", (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
|
||||
function! s:lod_map(map, plug)
|
||||
execute 'unmap '.a:map
|
||||
execute 'iunmap '.a:map
|
||||
call s:lod(a:plug)
|
||||
call s:lod(a:plug, ['plugin', 'ftdetect', 'after'])
|
||||
let extra = ''
|
||||
while 1
|
||||
let c = getchar(0)
|
||||
@@ -339,19 +381,35 @@ function! s:finish(pull)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:update_impl(pull, args)
|
||||
let threads = len(a:args) > 0 ? a:args[0] : get(g:, 'plug_threads', 16)
|
||||
function! s:names(...)
|
||||
return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0')
|
||||
endfunction
|
||||
|
||||
function! s:update_impl(pull, args) abort
|
||||
let args = copy(a:args)
|
||||
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
||||
\ remove(args, -1) : get(g:, 'plug_threads', 16)
|
||||
|
||||
let todo = empty(args) ? g:plugs :
|
||||
\ filter(copy(g:plugs), 'index(args, v:key) >= 0')
|
||||
|
||||
if empty(todo)
|
||||
echohl WarningMsg
|
||||
echo 'No plugin to '. (a:pull ? 'update' : 'install') . '.'
|
||||
echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
call s:prepare()
|
||||
call append(0, a:pull ? 'Updating plugins' : 'Installing plugins')
|
||||
call append(1, '['. s:lpad('', len(g:plugs)) .']')
|
||||
call append(1, '['. s:lpad('', len(todo)) .']')
|
||||
normal! 2G
|
||||
redraw
|
||||
|
||||
if has('ruby') && threads > 1
|
||||
call s:update_parallel(a:pull, threads)
|
||||
call s:update_parallel(a:pull, todo, threads)
|
||||
else
|
||||
call s:update_serial(a:pull)
|
||||
call s:update_serial(a:pull, todo)
|
||||
endif
|
||||
call s:finish(a:pull)
|
||||
endfunction
|
||||
@@ -380,10 +438,10 @@ function! s:update_progress(pull, cnt, bar, total)
|
||||
redraw
|
||||
endfunction
|
||||
|
||||
function! s:update_serial(pull)
|
||||
function! s:update_serial(pull, todo)
|
||||
let st = reltime()
|
||||
let base = g:plug_home
|
||||
let todo = copy(g:plugs)
|
||||
let todo = copy(a:todo)
|
||||
let total = len(todo)
|
||||
let done = {}
|
||||
let bar = ''
|
||||
@@ -397,7 +455,7 @@ function! s:update_serial(pull)
|
||||
if valid
|
||||
let result = a:pull ?
|
||||
\ s:system(
|
||||
\ printf('git checkout -q %s 2>&1 && git pull origin %s 2>&1',
|
||||
\ printf('git checkout -q %s 2>&1 && git pull origin %s 2>&1 && git submodule update --init --recursive 2>&1',
|
||||
\ s:shellesc(spec.branch), s:shellesc(spec.branch))) : 'Already installed'
|
||||
let error = a:pull ? v:shell_error != 0 : 0
|
||||
else
|
||||
@@ -410,10 +468,11 @@ function! s:update_serial(pull)
|
||||
endif
|
||||
execute 'cd '.base
|
||||
let result = s:system(
|
||||
\ printf('git clone --recursive %s -b %s %s 2>&1',
|
||||
\ printf('git clone --recursive %s -b %s %s 2>&1 && cd %s && git submodule update --init --recursive 2>&1',
|
||||
\ s:shellesc(spec.uri),
|
||||
\ s:shellesc(spec.branch),
|
||||
\ s:shellesc(substitute(spec.dir, '[\/]\+$', '', ''))))
|
||||
\ s:shellesc(substitute(spec.dir, '[\/]\+$', '', '')),
|
||||
\ s:shellesc(spec.dir)))
|
||||
let error = v:shell_error != 0
|
||||
endif
|
||||
cd -
|
||||
@@ -434,7 +493,7 @@ function! s:update_serial(pull)
|
||||
call setline(1, "Updated. Elapsed time: " . split(reltimestr(reltime(st)))[0] . ' sec.')
|
||||
endfunction
|
||||
|
||||
function! s:update_parallel(pull, threads)
|
||||
function! s:update_parallel(pull, todo, threads)
|
||||
ruby << EOF
|
||||
def esc arg
|
||||
%["#{arg.gsub('"', '\"')}"]
|
||||
@@ -448,7 +507,7 @@ function! s:update_parallel(pull, threads)
|
||||
iswin = VIM::evaluate('s:is_win').to_i == 1
|
||||
pull = VIM::evaluate('a:pull').to_i == 1
|
||||
base = VIM::evaluate('g:plug_home')
|
||||
all = VIM::evaluate('copy(g:plugs)')
|
||||
all = VIM::evaluate('copy(a:todo)')
|
||||
limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
|
||||
nthr = VIM::evaluate('a:threads').to_i
|
||||
cd = iswin ? 'cd /d' : 'cd'
|
||||
@@ -460,7 +519,7 @@ function! s:update_parallel(pull, threads)
|
||||
take1 = proc { mtx.synchronize { running && all.shift } }
|
||||
logh = proc {
|
||||
cnt = done.length
|
||||
tot = VIM::evaluate('len(g:plugs)') || tot
|
||||
tot = VIM::evaluate('len(a:todo)') || tot
|
||||
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
|
||||
$curbuf[2] = '[' + bar.ljust(tot) + ']'
|
||||
VIM::command('normal! 2G')
|
||||
@@ -558,7 +617,7 @@ function! s:update_parallel(pull, threads)
|
||||
"PlugClean required."].join($/)]
|
||||
else
|
||||
if pull
|
||||
bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && git pull origin #{branch} 2>&1"
|
||||
bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && git pull origin #{branch} 2>&1 && git submodule update --init --recursive 2>&1"
|
||||
else
|
||||
[true, skip]
|
||||
end
|
||||
@@ -566,7 +625,7 @@ function! s:update_parallel(pull, threads)
|
||||
else
|
||||
FileUtils.mkdir_p(base)
|
||||
d = esc dir.sub(%r{[\\/]+$}, '')
|
||||
bt.call "#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{d} 2>&1"
|
||||
bt.call "#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{d} 2>&1 && cd #{esc dir} && git submodule update --init --recursive 2>&1"
|
||||
end
|
||||
log.call name, result, ok
|
||||
end
|
||||
|
||||
@@ -296,6 +296,69 @@ Execute (Plug window in a new tab):
|
||||
q
|
||||
q
|
||||
|
||||
**********************************************************************
|
||||
~ On-demand loading / Partial installation/update ~
|
||||
**********************************************************************
|
||||
|
||||
Execute (Trying to execute on-demand commands when plugin is not installed):
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align', { 'on': ['EasyAlign', 'LiveEasyAlign'] }
|
||||
call plug#end()
|
||||
|
||||
Assert exists(':EasyAlign')
|
||||
Assert exists(':LiveEasyAlign')
|
||||
AssertThrows EasyAlign
|
||||
AssertThrows LiveEasyAlign
|
||||
Assert !exists(':EasyAlign')
|
||||
Assert !exists(':LiveEasyAlign')
|
||||
|
||||
Execute (New set of plugins):
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-fnr' " Depends on vim-pseudocl
|
||||
Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
|
||||
Plug 'junegunn/vim-redis', { 'for': 'redis' }
|
||||
call plug#end()
|
||||
|
||||
Execute (Check commands):
|
||||
Assert !exists(':FNR'), 'FNR command should not be found'
|
||||
Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
|
||||
|
||||
Execute (Partial PlugInstall):
|
||||
PlugInstall vim-fnr vim-easy-align
|
||||
PlugInstall vim-fnr vim-easy-align 1
|
||||
q
|
||||
|
||||
Execute (TODO Check dependent plugin):
|
||||
^ It is a known issue that when a dependent plugin is installed, it is not
|
||||
^ immediately added to runtimepath. It only becomes available when
|
||||
^ plug#end() is called.
|
||||
|
||||
Assert &rtp =~ 'pseudocl', &rtp
|
||||
|
||||
Given (Unaligned code):
|
||||
a=1
|
||||
aa=2
|
||||
|
||||
Execute (Check installed plugins):
|
||||
Assert exists(':FNR'), 'FNR command should be found'
|
||||
Assert exists(':EasyAlign'), 'EasyAlign command should be found'
|
||||
Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
|
||||
%EasyAlign=
|
||||
|
||||
Expect (Aligned code):
|
||||
a = 1
|
||||
aa = 2
|
||||
|
||||
Given (nothing):
|
||||
Execute (Partial PlugUpdate):
|
||||
PlugUpdate vim-redis
|
||||
q
|
||||
|
||||
Execute (On-demand loading based on filetypes):
|
||||
Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
|
||||
set ft=redis
|
||||
Assert exists(':RedisExecute'), 'RedisExecute command is now found'
|
||||
|
||||
Execute (Cleanup):
|
||||
call system('rm -rf '.temp_plugged)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user