[英]Automatically Quit Vim if NERDTree and TagList are the only 2 Buffers Left
I have this code taken from another StackOverflow user Conner, from this question Automatically quit Vim if NERDTree and TagList are the last and only buffers 我有这个代码取自另一个StackOverflow用户Conner,来自这个问题如果NERDTree和TagList是最后一个也是唯一的缓冲区,则自动退出Vim
(There wasn't an option for me to comment on that question, so my only option was to ask a new one). (我没有办法对这个问题发表评论,所以我唯一的选择就是问一个新的问题)。
The question is: How do I close Vim editor (in Linux Mint) if only NERDTree and TagList are the only two buffers left? 问题是:如果仅剩下NERDTree和TagList是仅有的两个缓冲区,如何关闭Vim编辑器(在Linux Mint中)?
The answer provided was: 提供的答案是:
" 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()
But that does not work properly. 但这不能正常工作。 Is closes whenever I close the last "exciting" buffer (one that is non-NERDTree or non-TagList), but it also closes whenever I try to open a new file from NERDTree (by double clicking on a filename in the "explorer").
每当我关闭最后一个“令人兴奋的”缓冲区(非NERDTree或non-TagList的缓冲区)时,它就会关闭,但是当我尝试从NERDTree中打开一个新文件时,它也会关闭(通过双击“资源管理器”中的文件名) )。
Honestly, I do not understand this code too well. 老实说,我不太了解这段代码。 I have tried to mess around with it but I couldn't get the results I would like.
我试图弄乱它,但无法获得想要的结果。
How do I alter this code to not close when I open a new file from NERDTree explorer? 从NERDTree资源管理器中打开新文件时,如何更改此代码使其不关闭?
Thank you, Conner, and the rest of the community! 谢谢Conner和社区其他成员!
From the Taglist manual, put on your .vimrc file 在“标签列表”手册中,放入.vimrc文件
let Tlist_Exit_OnlyWindow=1
I don't use NERDTree, but you may succeed with the following 我不使用NERDTree,但您可能会成功完成以下操作
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.