diff --git a/README.md b/README.md index 9de30ce..ce0dc37 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,38 @@ " NOTE: comments after Bundle command are not allowed.. ``` + + Sample `.vimrc` for the using of `localbundle` + + ```vim + + " load only once to improve vimrc reloading speed + if !exists("g:vimrc_bundle_loaded") + let g:vimrc_bundle_loaded=1 + set nocompatible + syntax on + filetype off + + " set it to 1 to enable it + " then vundle will only adding the localbundle dir to &rtp. + let g:vundle_local = 1 + " set the localbundle directory + " let g:vundle_local_dir = '~/.vim/localbundle' + + set rtp+=~/.vim/bundle/vundle + call vundle#rc() + Bundle 'gmarik/vundle' + + Bundle 'scrooloose/nerdtree' + + Bundle 'Rykka/colorv.vim' + Bundle 'Rykka/galaxy.vim' + + " ... + filetype plugin indent on " required! + endif "}}} + + ``` 3. Install configured bundles: diff --git a/autoload/vundle.vim b/autoload/vundle.vim index 1ac74e1..fa64270 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -25,6 +25,7 @@ com! -nargs=? -bang BundleClean com! -nargs=0 BundleDocs \ call vundle#installer#helptags(g:bundles) +com! -bang BundleUpdateLocal call vundle#installer#update_local('!' == '', ) if (has('signs')) sign define Vu_error text=! texthl=Error @@ -42,5 +43,15 @@ func! vundle#rc(...) abort let g:updated_bundles = [] let g:vundle_log = [] let g:vundle_changelog = ['Updated Bundles:'] + + let g:vundle_local = exists("g:vundle_local") ? g:vundle_local : 0 + let g:vundle_local_dir = exists("g:vundle_local_dir") ? + \ expand(g:vundle_local_dir) : expand('$HOME/.vim/localbundle', 1) + if filereadable(g:vundle_local_dir."/autoload/vundle.vim") && g:vundle_local + exe 'set rtp^='.fnameescape(g:vundle_local_dir) + exe 'set rtp+='.fnameescape(g:vundle_local_dir.'/after') + exe 'set rtp-='.fnameescape(g:bundle_dir) + endif + call vundle#config#init() endf diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 55c7d7d..8606497 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -1,14 +1,14 @@ func! vundle#config#bundle(arg, ...) let bundle = vundle#config#init_bundle(a:arg, a:000) - call s:rtp_rm_a() + if g:vundle_local==0 | call s:rtp_rm_a() | endif call add(g:bundles, bundle) - call s:rtp_add_a() + if g:vundle_local==0 | call s:rtp_add_a() | endif return bundle endf func! vundle#config#init() if !exists('g:bundles') | let g:bundles = [] | endif - call s:rtp_rm_a() + if g:vundle_local==0 | call s:rtp_rm_a() | endif let g:bundles = [] endf @@ -20,6 +20,10 @@ func! vundle#config#require(bundles) abort exec 'runtime! '.b.name.'/plugin/*.vim' exec 'runtime! '.b.name.'/after/*.vim' call s:rtp_rm(g:bundle_dir) + if g:vundle_local!=0 + exec 'runtime! '.b.name.'/autoload/*.vim' + call s:rtp_rm(b.rtpath) + endif endfor endf diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index 036a756..c5e7490 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -253,3 +253,68 @@ func! s:log(str) abort call add(g:vundle_log, '['.strftime(fmt).'] '.a:str) return a:str endf + +fun! vundle#installer#localdocs() abort + call s:helptags(g:vundle_local_dir) + return 'helptags' +endfun + +func! vundle#installer#local() abort + return s:update_local() +endf + +fun! s:update_local() abort "{{{ + + let local_dir = shellescape(g:vundle_local_dir) + let bundle_dir = shellescape(g:bundle_dir) + call s:log('') + call s:log('Remove dir of localbundle') + if has('win32') || has('win64') + let cmd = "rd /S /Q ".local_dir + else + let cmd = "rm -rf ".local_dir + endif + let out = s:system(cmd) + call s:log('$ '.cmd) + call s:log('> '.out) + + call mkdir(g:vundle_local_dir, "p") + + call s:log('') + call s:log('copy to localbundle ') + if has('win32') || has('win64') + let dirs = split(glob(g:bundle_dir.'/*/'),'\n') + for dir in dirs + let cmd = 'xcopy /E /Y /C /I '.shellescape(dir."*").' '.local_dir + let out = s:system(cmd) + call s:log('$ '.cmd) + call s:log('> '.out) + endfor + else + let cmd = "cp -rnl ".bundle_dir."/*/* ".local_dir + let out = s:system(cmd) + call s:log('$ '.cmd) + call s:log('> '.out) + endif + + if 0 != v:shell_error + return 'error' + else + return 'updated' + end + +endfun "}}} + +function! vundle#installer#update_local(bang,...) "{{{ + let bundles = (a:1 == '') ? + \ g:bundles : + \ map(copy(a:000), 'vundle#config#bundle(v:val, {})') + + let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec')) + call vundle#scripts#view('Installer',['" Update Bundle and install to '.expand(g:vundle_local_dir, 1)], names + ['LocalBundle','LocalHelptags']) + + call s:process(a:bang, (a:bang ? 'add!' : 'add')) + + call vundle#config#require(bundles) + +endfunction "}}} diff --git a/autoload/vundle/scripts.vim b/autoload/vundle/scripts.vim index 53a77e1..d0d5d05 100644 --- a/autoload/vundle/scripts.vim +++ b/autoload/vundle/scripts.vim @@ -109,6 +109,7 @@ func! vundle#scripts#view(title, headers, results) setl syntax=vim syn keyword vimCommand Bundle syn keyword vimCommand Helptags + syn keyword vimCommand LocalBundle LocalHelptags com! -buffer -bang -nargs=1 DeleteBundle \ call vundle#installer#run('vundle#installer#delete', split(,',')[0], ['!' == '', ]) @@ -122,6 +123,12 @@ func! vundle#scripts#view(title, headers, results) com! -buffer -bang -nargs=0 InstallHelptags \ call vundle#installer#run('vundle#installer#docs', 'helptags', []) + com! -buffer -bang -nargs=0 InstallLocalHelptags + \ call vundle#installer#run('vundle#installer#localdocs', 'localhelptags', []) + + com! -buffer -bang -nargs=0 InstallLocalBundle + \ call vundle#installer#run('vundle#installer#local', 'localbundle', []) + com! -buffer -nargs=0 VundleLog call s:view_log() com! -buffer -nargs=0 VundleChangelog call s:view_changelog() diff --git a/test/win_localrc.vim b/test/win_localrc.vim new file mode 100644 index 0000000..31346a1 --- /dev/null +++ b/test/win_localrc.vim @@ -0,0 +1,63 @@ +" vim -u test/vimrc +set nocompatible + +set nowrap +set et sw=4 +set noruler +set laststatus=2 +map :help +map :so % +let mapleader=" " +set bs=start +nno < << +nno > >> + +let root = '~/.vim/bundle' + +if !isdirectory(root) + mkdir(root,'p') +endif + +" NOTE: should change 'Rykka/vundle' to the offical repo +let src = 'http://github.com/Rykka/vundle.git' + +" let src = '~/.vim/bundle/vundle/.git' + +" Vundle Options +" let g:vundle_default_git_proto = 'git' + +if !isdirectory(root.'\vundle') + exec '!git clone '.src.' '.shellescape(root.'\vundle', 1) +endif + +filetype off +syntax on + +runtime macros/matchit.vim + +" set it to 1 then vundle will only adding the localbundle dir to &rtp. +let g:vundle_local = 1 +" set the default localbundle directory +"let g:vundle_local_dir = '~/.vim/localbundle' + +exec 'set rtp+='.root.'/vundle' + +call vundle#rc(root) + +Bundle "Rykka/vundle" +Bundle 'Rykka/colorv.vim' +Bundle 'Rykka/galaxy.vim' + +filetype plugin indent on " Automatically detect file types. + +set wildignore+=doc " should not break helptags +set wildignore+=.git " should not break clone +set wildignore+=.git/* " should not break clone +set wildignore+=*/.git/* +" TODO: helptags fails with this +" set wildignore+=doc/* " should not break clone +" set wildignore+=*/doc/* + +"au VimEnter * BundleInstall + +colorscheme galaxy