How do you disable a specific plugin in Vim?

扶醉桌前 提交于 2020-01-11 19:58:08

问题


I have Vim set up to use the excellent NERDTree plugin. However, there are some environments where I do not want this plugin to be loaded.

In my .vimrc I have a sections that are only run when specific environment variables are true. In one of these sections I would like to disable the loading of NERDTree but all of the information I've come across states how to disable all plugins, not just one.

Could someone demonstrate how to disable the loading of one specific plugin in Vim?


回答1:


Most plugins have a (re)inclusion guard.

Open the plugin, see the name of the guard, if any (if not, add one by yourself, and contact the author to make him fix his plugin), and finally set its value to 1 in your .vimrc. That's all.

I can't be more specific as "open, and look for the guard" as not all plugins use the same guards-naming policy. It's often g:loaded_pluginname though.

Regarding ftplugins, it becomes more tricky. The guard is a buffer-local variable. As such, it can't be specified into your .vimrc (as it would apply only to the first buffer you open). The easiest way would be to move your ftplugin from .vim/ftplugin to .vim/after/ftplugin, and to set the relevant anti-reinclusion guard to 1 in a ftplugin in your non-after hierarchy. As long as the ftplugin does not expect to be placed in after/ (or the contrary, it should be fine). Note: most ftplugins believe they are unique and (mis-)use the variable b:did_ftplugin as reinclusion guard.




回答2:


Add this line to your .vimrc

let g:loaded_nerdtree_exec_menuitem = 1


来源:https://stackoverflow.com/questions/2888970/how-do-you-disable-a-specific-plugin-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!