Load-on-demand with on option
				
					
				
			This commit is contained in:
		
							parent
							
								
									75efbd7b68
								
							
						
					
					
						commit
						1c2d394782
					
				
							
								
								
									
										13
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								README.md
									
									
									
									
									
								
							|  | @ -13,6 +13,8 @@ Somewhere between [Pathogen](https://github.com/tpope/vim-pathogen) and | ||||||
| - Parallel installation/update (requires | - Parallel installation/update (requires | ||||||
|   [+ruby](http://junegunn.kr/2013/09/installing-vim-with-ruby-support/)) |   [+ruby](http://junegunn.kr/2013/09/installing-vim-with-ruby-support/)) | ||||||
| - Smallest possible feature set | - Smallest possible feature set | ||||||
|  | - Branch/tag support | ||||||
|  | - On-demand loading | ||||||
| - Dependency resolution using `Plugfile` (experimental) | - Dependency resolution using `Plugfile` (experimental) | ||||||
| 
 | 
 | ||||||
| ### Cons. | ### Cons. | ||||||
|  | @ -36,6 +38,7 @@ call plug#begin('~/.vim/plugged') | ||||||
| 
 | 
 | ||||||
| Plug 'junegunn/seoul256.vim' | Plug 'junegunn/seoul256.vim' | ||||||
| Plug 'junegunn/vim-easy-align' | Plug 'junegunn/vim-easy-align' | ||||||
|  | Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } | ||||||
| " Plug 'user/repo1', 'branch_or_tag' | " Plug 'user/repo1', 'branch_or_tag' | ||||||
| " Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'devel' } | " Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'devel' } | ||||||
| " Plug 'git@github.com:junegunn/vim-github-dashboard.git' | " Plug 'git@github.com:junegunn/vim-github-dashboard.git' | ||||||
|  | @ -79,6 +82,16 @@ Plug 'tpope/vim-sensible' | ||||||
| call plug#end() | call plug#end() | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|  | ### On-demand loading of plugins | ||||||
|  | 
 | ||||||
|  | ```vim | ||||||
|  | " NERD tree will be loaded on the first invocation of NERDTreeToggle command | ||||||
|  | Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } | ||||||
|  | 
 | ||||||
|  | " Multiple commands | ||||||
|  | Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] } | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
| ### Dependency resolution | ### Dependency resolution | ||||||
| 
 | 
 | ||||||
| See [Dependency | See [Dependency | ||||||
|  |  | ||||||
							
								
								
									
										37
									
								
								plug.vim
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								plug.vim
									
									
									
									
									
								
							|  | @ -13,8 +13,9 @@ | ||||||
| " | " | ||||||
| "   Plug 'junegunn/seoul256.vim' | "   Plug 'junegunn/seoul256.vim' | ||||||
| "   Plug 'junegunn/vim-easy-align' | "   Plug 'junegunn/vim-easy-align' | ||||||
|  | "   Plug 'junegunn/goyo.vim', { 'on': 'Goyo' } | ||||||
| "   " Plug 'user/repo1', 'branch_or_tag' | "   " 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() | "   call plug#end() | ||||||
|  | @ -110,10 +111,17 @@ function! plug#end() | ||||||
| 
 | 
 | ||||||
|   filetype off |   filetype off | ||||||
|   for plug in values(g:plugs) |   for plug in values(g:plugs) | ||||||
|     let rtp = s:rtp(plug) |     if has_key(plug, 'on') | ||||||
|     execute "set rtp^=".rtp |       let commands = type(plug.on) == 1 ? [plug.on] : plug.on | ||||||
|     if isdirectory(rtp.'after') |       for cmd in commands | ||||||
|       execute "set rtp+=".rtp.'after' |         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 |     endif | ||||||
|   endfor |   endfor | ||||||
|   filetype plugin indent on |   filetype plugin indent on | ||||||
|  | @ -128,6 +136,25 @@ function! s:rtp(spec) | ||||||
|   return rtp |   return rtp | ||||||
| endfunction | 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(...) | function! s:add(...) | ||||||
|   let force = a:1 |   let force = a:1 | ||||||
|   let opts = { 'branch': 'master' } |   let opts = { 'branch': 'master' } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user