Skip to content

Instantly share code, notes, and snippets.

@da99
Last active April 2, 2022 21:52
Show Gist options
  • Save da99/576c3e179ce1795c7b1c9a7db7b43d4f to your computer and use it in GitHub Desktop.
Save da99/576c3e179ce1795c7b1c9a7db7b43d4f to your computer and use it in GitHub Desktop.
Close NeoVim terminal on Exit 0 (successful exit), but keep it open when the command/shell exits with a failure.
" Start terminal in insert mode:
autocmd TermOpen * IndentLinesDisable | startinsert
" In NeoVim, lookup `terminal-status`
:help terminal-status
"This will give you information on how to auto-close the terminal on succesful exit:
"
" From the Neovim help documentation:
"- The TermClose event gives the terminal job exit code in the v:event
" "status" field. For example, this autocmd closes terminal buffers if the job
" exited without error:
" autocmd TermClose * if !v:event.status | exe 'bdelete! '..expand('<abuf>') | endif
"
autocmd TermClose * if !v:event.status | exe 'bdelete! '..expand('<abuf>') | endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment