4

我最近将 NERDTree 和 NERDTreeTabs 添加到我的 vim 配置中,对此我感到非常高兴。

但是,我想进一步配置它并具有以下行为:

Ctrl+ Left:

  • 如果在 NERDTree 内,什么也不做。

  • 如果在编辑的文件中,请转到打开的 NERDTree,如果不存在则先打开一个。我想NERDTreeTabsToggle应该使用它,但要使用它,我必须能够检测 NERDTree 是否已经打开,而不是通过“切换”它来关闭它。

Ctrl+ Right:

  • 如果在 NERDTree 中,请返回编辑的文件而不关闭 NERDTree。(就像Ctrl- wRight会做的那样。)

  • 如果在编辑后的文件中,隐藏/关闭 NERDTree。

但是,我的 Vim 脚本技能对我来说太低了,无法获得任何令人满意的结果。例如,我不知道如何检查当前活动窗口是什么或如何编写适当的条件语句。

有人可以帮我吗?

谢谢你。

4

1 回答 1

6

If finally found a way.

I edited the nerdtree_plugin/vim-nerdtree-tabs.vim file, adding these functions:

" === 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

I also made a pull-request to the author to ask him if he wants to add theses functions upstream.

The author added my pull-request to the main repository, so with the next release, you can just call the functions directly.

Hope it helps people.

于 2012-07-04T09:57:17.017 回答