如果 NERDTree 是最后且唯一的缓冲区,则自动退出 vim
我的 .vimrc 中有以下内容:
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open NERDTree by default
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
因此,
% vim file.txt
打开 NERDTree 并将光标聚焦在 file.txt 缓冲区中。我进行编辑,然后在缓冲区上点击 :q ,然后剩下 . 。 。书呆子树。这很烦人。
我可以使用 :qa 关闭所有缓冲区,然后退出 vim,但我习惯了 :q 转义。所以我想知道是否有一种方法可以检测唯一剩余的缓冲区是 NERDTree,并“统一”这两个缓冲区,以达到以下目的:q
编辑
询问,你们将收到: https://github.com/scrooloose/nerdtree/issues#issue/21
I have the following in my .vimrc:
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open NERDTree by default
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
So,
% vim file.txt
opens NERDTree and focuses the cursor in the file.txt buffer. I make my edits, and hit :q on the buffer, and I'm left with . . . NERDTree. This is annoying.
I could use :qa to close all buffers, and exit vim, but I'm used to the :q trope. So I'm wondering if there's a way to detect that the only remaining buffer is NERDTree, and "unify" the two buffers, for purposes of :q
Edit
Ask and ye shall receive: https://github.com/scrooloose/nerdtree/issues#issue/21
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
NERDTree 问题列表上已发布了用于执行此操作的脚本。在 GitHub 上查看 nerdtree 的 issue-21。
这将导致您的 vimrc 此处使用单行命令:
A script to do exactly this has been posted on the NERDTree issue list. Checkout issue-21 on GitHub for nerdtree.
This leads to the single line command for your vimrc here:
来自我的 vimrc,基于 janus 仓库。
增强功能:如果仅留下快速修复窗口,也可以关闭。
它使用
BufEnter
自动命令来代替,这是&bt
正常工作所必需的。From my vimrc, based on a version from janus repo.
Enhancements: also close if only a quickfix window is left.
It uses the
BufEnter
autocommand instead, which is required for&bt
to work properly.需要实现的想法:
您可以编写一个函数,在调用时检查唯一剩余的缓冲区(或者可能是唯一的非帮助缓冲区,如果您愿意的话)是否是 NERDTree 缓冲区,如果是,则删除它(或就退出了)。
然后,每当缓冲区被删除/隐藏/无论您实际发生什么时,都让自动命令运行它:q(承认我不完全确定,这让我感到羞愧!)。
An idea in need of implementation:
You could write a function which, when called, checks if the only buffer remaining (or perhaps the only non-help buffer, if you prefer) is a NERDTree buffer and, if so, deletes it (or just quits).
Then have an autocmd run it whenever a buffer is deleted / hidden / whatever actually happens when you :q (it shames me to admit I'm not entirely sure!).
您可以
:cabbrv q qa
但我建议不要这样做,因为当您真正想要q
时您会忘记它。You could
:cabbrv q qa
but I'd advise against that because you'll forget about it when you actually wantq
.我喜欢这样做:
cmap bq :bufdo q
在命令模式下通过两次按键关闭所有缓冲区。I like to do this:
cmap bq :bufdo q<CR>
to close all buffers with two keystrokes in command mode.