简体   繁体   English

你如何禁用Vim中的特定插件?

[英]How do you disable a specific plugin in Vim?

I have Vim set up to use the excellent NERDTree plugin. 我让Vim设置为使用优秀的NERDTree插件。 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. 在我的.vimrc中,我有一个仅在特定环境变量为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. 在其中一个部分中,我想禁用NERDTree的加载,但我遇到的所有信息都说明了如何禁用所有插件,而不仅仅是一个。

Could someone demonstrate how to disable the loading of one specific plugin in Vim? 有人可以演示如何在Vim中禁用一个特定插件的加载吗?

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. 打开插件,看看防护的名称,如果有的话(如果没有,自己添加一个,并联系作者让他修复他的插件),最后在.vimrc中将其值设置为1。 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. 它通常是g:loaded_pluginname

Regarding ftplugins, it becomes more tricky. 关于ftplugins,它变得更加棘手。 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). 因此,它无法指定到.vimrc中(因为它仅适用于您打开的第一个缓冲区)。 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. 最简单的方法是将你的ftplugin从.vim/ftplugin移动到.vim/after/ftplugin ,并在非后层次结构的ftplugin中将相关的反重新保护设置为1。 As long as the ftplugin does not expect to be placed in after/ (or the contrary, it should be fine). 只要ftplugin不希望放在after/ (或相反,它应该没问题)。 Note: most ftplugins believe they are unique and (mis-)use the variable b:did_ftplugin as reinclusion guard. 注意:大多数ftplugins认为它们是唯一的并且(错误地)使用变量b:did_ftplugin作为重新加入防护。

将此行添加到.vimrc

let g:loaded_nerdtree_exec_menuitem = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM