vim - 如何自定义 NERDTree 行为

标签 vim customization nerdtree

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

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

Ctrl+左:

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

  • Ctrl+右:
  • 如果在 NERDTree 内,请在不关闭 NERDTree 的情况下返回编辑的文件。 (就像 Ctrl-w,Right 会做的那样。)
  • 如果在编辑过的文件中,隐藏/关闭 NERDTree。

  • 然而,我的 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/

    相关文章:

    php - 更改 PayPal 中默认字段的文本?

    vim - 更改 NERDtree 中的驱动器号

    vim - vim nerdtree vs “E:”资源管理器?

    vim - 使用vim,如何在特定路径的子目录中的文件中使用autocmd?

    vim - 在用户定义命令中使用行号

    c - 如何为当前项目配置 .ycm_extra_conf.py include PATH

    vim - 无法使用 macvim 8.2.319 在 MacOS Catalina 上运行 NERDTree 和 lightline

    vim - 如何从 :messages 复制到剪贴板最后 3 行

    unity3d - 除了在 Unity3D 中使用 "Assets/Gizmos"之外,如何使用自定义脚本图标

    macos - 在 netbeans 中更改文件选项卡颜色