我最近将 NERDTree 和 NERDTreeTabs 添加到我的 vim 配置中,我对此感到非常高兴。
但是,我想进一步配置它并具有以下行为:
Ctrl+左:
NERDTreeTabsToggle
应该使用,但要使用它,我必须能够检测到 NERDTree 是否已经打开,而不是通过“切换”它来关闭它。 Ctrl+右:
然而,我的 Vim 脚本技能对我来说太低了,无法获得任何令人满意的结果。例如,我不知道如何检查当前事件窗口是什么或如何编写适当的条件语句。
有人可以帮我吗?
谢谢你。
最佳答案
如果最后找到了方法。
我编辑了 nerdtree_plugin/vim-nerdtree-tabs.vim
文件,添加这些功能:
" === Stepped Open/Close functions ===
" focus the NERDTree view, creating one first if none is present
fun! s:NERDTreeSteppedOpen()
if !s:IsCurrentWindowNERDTree()
if s:IsNERDTreeOpenInCurrentTab()
call s:NERDTreeFocus()
else
call s:NERDTreeMirrorOrCreate()
endif
endif
endfun
" unfocus the NERDTree view or closes it if it hadn't had focus at the time of
" the call
fun! s:NERDTreeSteppedClose()
if s:IsCurrentWindowNERDTree()
call s:NERDTreeUnfocus()
else
let l:nerdtree_open = s:IsNERDTreeOpenInCurrentTab()
if l:nerdtree_open
silent NERDTreeClose
endif
endif
endfun
我也做了一个 pull-request向作者询问他是否要在上游添加这些功能。
作者把我的pull-request加到了主仓库,下个版本直接调用函数就可以了。
希望它可以帮助人们。
关于vim - 如何自定义 NERDTree 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11325044/