0

我正在使用病原体来管理我在 vim 中的插件,并且我的 vimrc 中有一个部分,只有在未安装/不会加载某个插件时我才想运行该部分。例如

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

在大多数情况下可能会起作用的两个选项是检查 dwm.vim 是否在g:pathogen_disabled和/或检查目录是否.vim/bundle/dwm.vim存在。

然而,这些检查似乎有些脆弱。例如,如果我根本没有 dwm,则检查 dwm.vim 不禁用病原体是不够的,并且无论出于何种原因 dwm.vim 位于某个非标准位置,但仍使其进入runtimepath路径检查将不起作用.

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?

4

2 回答 2

3

Most plugins have a (re)inclusion guard. Usually named g:loaded_pluginname. Using this and the after directory you can conditionally load your mappings.

Put the following in ~/.vim/after/plugin/dwm.vim:

if !get(g:, 'loaded_dwm', 0)
  nnoremap <C-j> <C-w>j
  nnoremap <C-k> <C-w>k
  nnoremap <C-l> <C-w>l
endif

For more help see:

:h write-plugin
:h after-directory
:h get()
于 2015-08-28T17:43:25.457 回答
2

Add this after pathogen#infect():

if globpath(&runtimepath, 'dwm.vim', 1) !=# ''
    " dwm.vim caught in the act
endif
于 2015-08-28T16:41:22.820 回答