Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way of adding a specific addon after vim is already started? #78

Open
skeept opened this issue Nov 26, 2012 · 2 comments
Open

Comments

@skeept
Copy link

skeept commented Nov 26, 2012

There are some plugins that I rarely use but when I need to use them I first have to edit my vimrc and remove them from the list of disabled plugins and start vim again.

Would it be possible to have a function either in pathogen, or based on pathogen that would allow the following:

:PathogenEnable pluginName
:PathogenEnable /path/to/other/plugin

in the first version the plugin would be in the bundle directory in the second case the plugin could be in a arbitrary directory.

Thank you for your work on this plugin.

@tpope
Copy link
Owner

tpope commented Jan 1, 2013

Probably possible, but super tricky. The first challenge is to add it to the runtime path. What position does it belong in? The OCD part of me wants to inject it into the exact spot it would have appeared if it had been loaded with Vim. But I guess we could get by with something more predictable.

The harder part is actually loading plugins after they've been added. Do we :source them? :runtime them? Do we need to dispatch any autocmds?

@lifepillar
Copy link
Contributor

The harder part is actually loading plugins after they've been added.

Indeed. In general, you need plugin-specific code for that. For example, YouCompleteMe is bootstrapped through a function called on a VimEnter event, which needs to be called manually if the plugin is loaded later.

Anyway, I have this code in my .vimrc, which mostly does what the OP is asking for:

  " 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
    " Note that this loads only one file (which is usually fine):
    runtime plugin/*.vim
    " Note that this uses the plugin name as typed by the user:
    execute 'runtime! after/plugin/**/' . a:plugin_name . '.vim'
    " Plugin-specific activation
    if tolower(a:plugin_name) == 'youcompleteme'
      call youcompleteme#Enable()
    endif
  endf

  " See h :command
  fun! s:loadPluginCompletion(argLead, cmdLine, cursorPos)
    return filter(copy(g:pathogen_blacklist), "v:val =~? '^" . a:argLead . "'")
  endf

  command! -nargs=1 -complete=customlist,s:loadPluginCompletion LoadPlugin call <sid>loadPlugin(<q-args>)

lifepillar pushed a commit to lifepillar/vimrc that referenced this issue Sep 20, 2015
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:

    tpope/vim-pathogen#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants