【问题标题】:Automatically Quit Vim if NERDTree and TagList are the only 2 Buffers Left如果 NERDTree 和 TagList 是仅剩的 2 个缓冲区,则自动退出 Vim
【发布时间】:2013-11-05 06:26:18
【问题描述】:

我有这个代码来自另一个 StackOverflow 用户 Conner,来自这个问题 Automatically quit Vim if NERDTree and TagList are the last and only buffers

(我无法对这个问题发表评论,所以我唯一的选择是问一个新问题)。

问题是:如果只剩下 NERDTree 和 TagList 两个缓冲区,我该如何关闭 Vim 编辑器(在 Linux Mint 中)?

提供的答案是:

" If only 2 windows left, NERDTree and Tag_List, close vim or current tab
fun! NoExcitingBuffersLeft()
  if winnr("$") == 3
    let w1 = bufname(winbufnr(1))
    let w2 = bufname(winbufnr(2))
    let w3 = bufname(winbufnr(3))
    if (exists(":NERDTree")) && (w1 == "__Tag_List__" || w2 == "__Tag_List__" || w3 == "__Tag_List__")
      if tabpagenr("$") == 1
        exec 'qa'
      else
        exec 'tabclose'
      endif
    endif
  endif
endfun
autocmd BufWinLeave * call NoExcitingBuffersLeft()

但这不能正常工作。每当我关闭最后一个“令人兴奋的”缓冲区(一个非 NERDTree 或非 TagList)时它就会关闭,但每当我尝试从 NERDTree 打开一个新文件时它也会关闭(通过双击“资源管理器”中的文件名) )。

老实说,我不太了解这段代码。我试图弄乱它,但我无法得到我想要的结果。

当我从 NERDTree 资源管理器打开新文件时,如何更改此代码以不关闭?

感谢 Conner 和社区的其他成员!

【问题讨论】:

    标签: linux vim nerdtree taglist


    【解决方案1】:

    从 Taglist 手册中,放入你的 .vimrc 文件

    let Tlist_Exit_OnlyWindow=1
    

    我不使用 NERDTree,但您可以通过以下方式成功

    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多