The vim version has a ++close option that automatically closes the terminal when the job terminates, but since the NeoVim terminal came first it doesn't have that feature.
I need this because i am trying to run programs directly from vim, but i regularly make
curses applications which the popup window you get from :!python % can't handle, so i need the terminal window.
I am using NeoVim on arch linux if that's relevant.
You can accomplish this by using an autocmd on the TermClose event. From the neovim manual (:help terminal):
autocmd TermClose * if !v:event.status | exe 'bdelete! '..expand('<abuf>') | endif
I didn't care about the exit status, so for my personal configuration I simplified it to
autocmd TermClose * execute 'close!'
Finally, since I am using lua in ~/.config/nvim/init.lua with neovim, I translated it to lua as follows:
vim.api.nvim_create_autocmd("TermClose", {
callback = function()
vim.cmd("close")
end
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With