如果 NERDTree 是最后一个且唯一的缓冲区,则自动退出 vim [英] Automatically quit vim if NERDTree is last and only buffer

查看:63
本文介绍了如果 NERDTree 是最后一个且唯一的缓冲区,则自动退出 vim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .vimrc 中有以下内容:

I have the following in my .vimrc:

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open NERDTree by default
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p

所以,

% vim file.txt

打开 NERDTree 并将光标聚焦在 file.txt 缓冲区中.我进行了编辑,然后在缓冲区上点击 :q ,我只剩下 ...书呆子树.这很烦人.

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.

我可以使用 :qa 关闭所有缓冲区,然后退出 vim,但我已经习惯了 :q 比喻.所以我想知道是否有一种方法可以检测到唯一剩余的缓冲区是 NERDTree,并统一"这两个缓冲区,以便:q

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

编辑

询问您将收到:https://github.com/scrooloose/nerdtree/问题#issue/21

推荐答案

一个脚本已经发布在 NERDTree 问题列表上.在 GitHub 上查看 nerdtree 的 issue-21.

A script to do exactly this has been posted on the NERDTree issue list. Checkout issue-21 on GitHub for nerdtree.

这会导致您的 vimrc 的单行命令此处:

This leads to the single line command for your vimrc here:

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

这篇关于如果 NERDTree 是最后一个且唯一的缓冲区,则自动退出 vim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆