如何退出 shell 以 :bel terminal ++noclose cleaning closing window 开始的会话

How to exit out of shell session started with :bel terminal ++noclose cleaning closing window

我正在 vim 8.1.x Mac OS X.

我的 vimrc

中有以下内容
autocmd VimEnter * :bel terminal ++noclose

目的是在vim底部打开一个终端。

  1. 当我试图通过关闭所有缓冲区
  2. 退出vim
    :qa

底部不退出终端

  1. 我在终端中手动输入 exit 退出。终端已退出,但终端缓冲区仍处于打开状态。

如何很好地退出 vim 关闭所有 windows 包括终端?

来自 E947 的 Vim 文档:

So long as the job is running, the buffer is considered modified and Vim cannot be quit easily, see abandon.

您可以使用几个选项。一种是使用:qa!退出。另一种是设置一个 autocmd 以在您退出时终止所有终端 windows:

autocmd ExitPre * for i in term_list() | exe ':bd! ' . i | endfor

这将挂钩 ExitPre 事件并在该事件发生时删除其中包含终端的所有缓冲区。但是请注意,如果您的退出因为另一个缓冲区被修改而中止,那么您的终端仍将关闭。没有办法避免这种情况,因为 Vim 不会区分修改的终端和其他修改的缓冲区。