Chetan
Chetan

Reputation: 13

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

I am using vim 8.1.x on Mac OS X.

I have following in my vimrc

autocmd VimEnter * :bel terminal ++noclose

The intention is to have a terminal open at bottom in vim.

  1. When I try to exit vim by closing all Buffers
    :qa

It does not exit the terminal at bottom

  1. I have manually type exit in terminal to exit. The terminal is exited but terminal Buffer is still open.

How can nicely exit out of vim closing all windows including terminal?

Upvotes: 0

Views: 205

Answers (1)

bk2204
bk2204

Reputation: 76784

From the Vim documentation for E947:

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

There are a few options you can use. One is to use :qa! to quit. Another is to set an autocmd to terminate all terminal windows when you exit:

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

This hooks the ExitPre event and deletes all buffers with terminals in them when that event occurs. Note, however, that if your exit is aborted because another buffer is modified, then your terminals will still be closed. There isn't a way to avoid that, since Vim won't distinguish between modified terminals and other modified buffers.

Upvotes: 1

Related Questions