【问题标题】:How-to customize NERDTree behavior如何自定义 NERDTree 行为
【发布时间】:2012-07-05 15:03:40
【问题描述】:

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

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

Ctrl+

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

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

Ctrl+:

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

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

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

有人可以帮我吗?

谢谢。

【问题讨论】:

    标签: vim customization nerdtree


    【解决方案1】:

    如果终于找到了方法。

    我编辑了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 添加到主仓库,所以下个版本,你可以直接调用函数。

    希望它对人们有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-05
      • 2017-03-04
      相关资源
      最近更新 更多