From vim/src/eval.c :

static void eval_job_process_exit_cb(Process *proc, int status, void *d) { [..] if (data->term && !data->exited) { data->exited = true; char msg[sizeof("\r

[Process exited ]") + NUMBUFLEN]; snprintf(msg, sizeof msg, "\r

[Process exited %d]", proc->status); terminal_close(data->term, msg); } [..] }

There is no setting or something else to disable this message here. It is always displayed. The only other place where terminal_close() is called is from the close_buffer() function, which is the :close command (among others). I'm not sure if you can send the :close command from a script within the terminal to Neovim; I don't think so.

The first way to fix this is to modify the way you open the terminal:

fun! TermTest(cmd) call termopen(a:cmd, {'on_exit': 's:OnExit'}) endfun fun! s:OnExit(job_id, code, event) dict if a:code == 0 close endif endfun

The on_exit callback gets run before the message is displayed, so we can use that to close this buffer. The parameters seem undocumented ( :help jobstart merely mentions "exit event handler"), but found some information on a random internet page where a Neovim developer posted it.

If you can't modify the way the terminal gets opened you can still sort-of do the same by (ab)using the TermClose autocommand:

augroup terminal autocmd! autocmd TermClose * if getline('$') == 'Exit 0' | close | endif augroup end