From 44ca7975516c5bdf48478f88e0ea07f99be8fb3d Mon Sep 17 00:00:00 2001 From: Lifepillar Date: Sun, 20 Sep 2015 21:04:28 +0200 Subject: [PATCH] Enable lazy loading of plugins. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pathogen has a g:pathogen_blacklist variable that may be used to specify a list of plugins that should not be loaded at startup (btw, it also supports an undocumented $VIMBLACKLIST variable to temporarily disable plugins). Currently, I use that list to disable YouCompleteMe, which significantly increases the startup time, and which I need only when using some programming languages (e.g., Python). Enabling plugins at runtime is “super-tricky” in general: https://github.com/tpope/vim-pathogen/issues/78 (YCM being a good example, since it requires to call a function to enable it), but I don’t need a completely general approach in my personal vimrc, so s:loadPlugin() should be good enough. --- vimrc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/vimrc b/vimrc index 6c2ff6b..38085df 100644 --- a/vimrc +++ b/vimrc @@ -40,6 +40,7 @@ filetype plugin on " Enable loading the plugin files for specific file types. filetype indent on " Load indent files for specific file types. runtime bundle/pathogen/autoload/pathogen.vim " Load Pathogen. + let g:pathogen_blacklist = ['youcompleteme'] execute pathogen#infect() set sessionoptions-=options " See FAQ at https://github.com/tpope/vim-pathogen. set autoread " Re-read file if it is changed by an external program. @@ -67,6 +68,22 @@ echohl NONE endf + " Enable a blacklisted plugin. + fun! s:loadPlugin(plugin_name) + " Remove the plugin from Pathogen's blacklist + call filter(g:pathogen_blacklist, "v:val !=? '" . a:plugin_name ."'") + " Update runtimepath + call pathogen#surround($HOME . "/.vim/bundle/" . tolower(a:plugin_name)) + " Load the plugin + runtime plugin/**/*.vim + " Plugin-specific activation + if tolower(a:plugin_name) == 'youcompleteme' + call youcompleteme#Enable() + endif + endf + + command! -nargs=1 LoadPlugin call loadPlugin() + " Set the tab width in the current buffer (see also http://vim.wikia.com/wiki/Indenting_source_code). fun! s:setLocalTabWidth(w) let l:twd = a:w > 0 ? a:w : 1 " Disallow non-positive width