vim-pathogen icon indicating copy to clipboard operation
vim-pathogen copied to clipboard

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

Open skeept opened this issue 13 years ago • 2 comments

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.

skeept avatar Nov 26 '12 16:11 skeept

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?

tpope avatar Jan 01 '13 03:01 tpope

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 avatar Sep 20 '15 19:09 lifepillar