I'm looking to be able to close a terminal buffer without unloading it, as I would with a normal buffer and either hidden or bufhidden=hide set. It appears, though, that said options are ignored for terminal buffers. Note that I'm using vim 8.2.

Here's a reproducible example:

vim -u NONE
:set hidden
:vnew regular_buffer


  1 %a   "[No Name]"                    line 1
  2 #h   "regular_buffer"               line 0

next, create a terminal buffer:

:call term_start('ls', {'term_name': 'terminal_test'})

and the new buffer list:

  1 #a   "[No Name]"                    line 1
  2  h   "regular_buffer"               line 0
  3 %aF  "terminal_test [finished]"     line 1

now, close the terminal buffer:


and again show the buffer list:

  1 %a   "[No Name]"                    line 1
  2 #h   "regular_buffer"               line 0

Trying to reopen the buffer (:b3) confirms it no longer exists. How can I keep my terminal buffer loaded (and in the buffer list) after closing its window?


1 Answer 1


Terminal buffer is special:

When the job has finished and no changes were made to the buffer: closing the window will wipe out the buffer.

Change buffer type will stop this.


After job finished, clear buffer type:

setlocal buftype=

This also works:

setlocal modifiable
" make any change, the 1st change will convert terminal buffer to be a normal buffer.

See doc after :h E948 for detail.


Pass this options to term_start:

{ 'term_finish' : 'open',  'term_opencmd' : 'call setbufvar(%d, "&buftype", "")' }

It will clear buffer type when the job is finished, the %d will be replaced with terminal buffer number.

See :h term_start for detail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.