Reputation: 736
I have two different projects that I'm working on (let's call them projA and projB) that have their own Vim plugins.
Each plugin folder has an ftdetect, ftplugin, plugin and syntax subfolder, and each deals with the same type of files (.cpp, .html, etc).
If I load both sets of plugins then nothing I want works right so I need a way to only load the plugin that corresponds to the project I'm working on.
My idea is to detect what my current working directory is via getcwd()
and then only load the relevant plugin, but I have no idea how to manually load a single plugin.
I'm currently using Vundle to manage the rest of my plugins.
Upvotes: 2
Views: 4222
Reputation: 34293
vim-plug
The vim-plug
plugin manager supports loading plugins conditionally.
This is straight from their readme:
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
Upvotes: 5
Reputation: 172500
Package managers like Vundle and Pathogen separate each plugin into its own subtree and concatenate all those paths into the 'runtimepath'
option so that Vim considers all of them. That makes it particularly simple to disable plugins: Just prevent the inclusion of the plugin's subtree into 'runtimepath'
.
Vundle references plugins in ~/.vimrc
via Bundle 'foo/bar'
commands, so you just have to put a conditional around it:
if getcwd() ==# '/work/cpp'
Bundle example/cpp
else
Bundle example/other
endif
With a conventional, single ~/.vim/
configuration hierarchy, you'd have to resort to suppressing plugin loads by setting the canonical g:loaded_PluginName
inclusion guard. This requires support from the plugin, and mostly won't work for ftplugins, indent, and syntax scripts.
Upvotes: 4