vimvim-pluginpathogen

In vim with pathogen, how can I check if a plugin will be loaded?


I'm using pathogen to manage my plugins in vim, and I have a section in my vimrc that I would like to run only if a certain plugin isn't installed/won't be loaded. E.g.

if(dwm.vim not in use)
  nnoremap <C-h> <C-w>h
  nnoremap <C-j> <C-w>j
  nnoremap <C-k> <C-w>k
  nnoremap <C-l> <C-w>l
endif

The two options that would probably work in most cases are to check if dwm.vim is in g:pathogen_disabled and/or to check if the directory .vim/bundle/dwm.vim exists.

However these checks seem somewhat brittle. For example if I don't have dwm at all checking for dwm.vim not to be pathogen disabled is insufficient, and if for whatever reason dwm.vim is in some nonstandard location that still makes it into the runtimepath the path check won't work.

The whole point of pathogen is to make managing my runtimepath easier, so an elegant solution would be to search this path. But searching the help, the pathogen source, google, and here revealed no easy way to do this. Can I do this in vim/pathogen natively? Is there a plugin that will do this for me? Should I not be doing this at all, since the cases where the checks fail are fairly corner-casey and won't happen as long as I manage my plugins properly?


Solution

  • Add this after pathogen#infect():

    if globpath(&runtimepath, 'dwm.vim', 1) !=# ''
        " dwm.vim caught in the act
    endif