From c6faf362a3da101f513d3df7a7512e025a83f73b Mon Sep 17 00:00:00 2001 From: Rainux Luo Date: Sat, 22 Oct 2011 02:58:38 +0800 Subject: [PATCH] Manually bind and load scripts via BundleBind! with tags --- README.md | 5 +++++ autoload/vundle.vim | 4 ++-- autoload/vundle/config.vim | 31 +++++++++++++++++++++++++++---- doc/vundle.txt | 31 +++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 86b252c..856b953 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ Bundle 'git://git.wincent.com/command-t.git' " ... + " Slow scripts which will not be bound and loaded at Vim startup. + " When needed, you can manually bind them via `BundleBind!` command, + " run `:help Bundle-option-bind` and `:help BundleBind!` for more details. + Bundle 'c.vim', {'bind': 0, 'tags': ['c']} + filetype plugin indent on " required! " " Brief help diff --git a/autoload/vundle.vim b/autoload/vundle.vim index 54586cc..ca44829 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -7,8 +7,8 @@ com! -nargs=+ Bundle \ call vundle#config#bundle() -com! -nargs=0 -bang BundleBind -\ call vundle#config#bind() +com! -nargs=* -bang BundleBind +\ call vundle#config#bind() com! -nargs=? -bang -complete=custom,vundle#scripts#complete BundleInstall \ call vundle#installer#new('!' == '', ) diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 14e4915..1831d2f 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -3,10 +3,16 @@ func! vundle#config#bundle(arg, ...) call add(g:bundles, bundle) endf -func! vundle#config#bind() - call s:rtp_rm(g:bundles) - let bind_bundles = filter(copy(g:bundles), 'v:val.bind') - call vundle#config#require(bind_bundles) +func! vundle#config#bind(...) + if a:0 == 0 + call s:rtp_rm(g:bundles) + let bind_bundles = filter(copy(g:bundles), 'v:val.bind') + call vundle#config#require(bind_bundles) + else + let matched_bundles = filter(copy(g:bundles), + \ 's:is_tags_matched(v:val, '.string(a:000).')') + call vundle#config#require(matched_bundles) + end endf func! vundle#config#init() @@ -79,6 +85,23 @@ func! s:rtp_add(bundles) abort endfor endf +func! s:is_tags_matched(bundle, tags) + if !has_key(a:bundle, 'tags') + return 0 + endif + + let is_matched = 0 + for tag in a:bundle.tags + let is_matched = index(a:tags, tag) != -1 + + if is_matched + break + endif + endfor + + return is_matched +endf + func! s:expand_path(path) abort return simplify(expand(a:path)) endf diff --git a/doc/vundle.txt b/doc/vundle.txt index 185eb90..8e2c6ee 100644 --- a/doc/vundle.txt +++ b/doc/vundle.txt @@ -74,6 +74,12 @@ in order to install/search [all available vim scripts] Bundle 'git://git.wincent.com/command-t.git' " ... + " Slow scripts which will not be bound and loaded at Vim startup. + " When needed, you can manually bind them via `BundleBind!` command, + " run `:help |Bundle-option-bind|` and `:help |BundleBind!|` for more + " details. + Bundle 'c.vim', {'bind': 0, 'tags': ['c']} + filetype plugin indent on " required! " or " filetype plugin on " to not use the indentation settings set by plugins @@ -108,6 +114,23 @@ equals full uri > NOTE: Vundle defaults to http:// protocol for the short URIs + *Bundle-option-bind* +If some of your scripts will slow down your Vim startup, and you don't really +often need them, you have an option to disable bind them at Vim startup: > + + Bundle 'c.vim', {'bind': 0} + +When you need, these scripts can be bound manually via |BundleBind!| command. + + *Bundle-option-tags* +Scripts can be grouped via tags option: > + + Bundle 'c.vim', {'tags', ['c', 'slow']} + Bundle 'bash-support.vim', {'tags', ['bash', 'slow']} + +Currently the only usage of tags is to allow you manually bind slow scripts +when needed, but group scripts by tags should be useful in the future. + *BundleBind!* `Bundle` command just tell Vundle which scripts you want to use, it doesn't tell Vim load them, i.e, it doesn't update the 'runtimepath' option of Vim. @@ -119,6 +142,14 @@ The benefit of use an extra command to update 'runtimepath' is, we can make Vim startup much faster while keeping 'runtimepath' ordered according to the bundles declarations. +You can run `BundleBind!` manually to bind and load those scripts which +haven't get bound and loaded at Vim startup: > + + :BundleBind! slow + +`BundleBind!` can accept any number of tags, just use space to separate them: +> + :BundleBind! c bash ruby javascript 4.2 INSTALL SCRIPTS ~ *vundle-scripts-install* *BundleInstall*