How to close terminal floating window when programe exited
jonahfang opened this issue · comments
My config like this:
{ "<leader>g", mode = {"n"}, function()
require("detour").Detour()
vim.cmd.terminal(cmd)
vim.cmd('startinsert')
vim.bo.bufhidden = 'delete' -- close the terminal when window closes
end},
I have a solution but it doesn't work sometimes:
-- close when program exits
vim.cmd([[
autocmd TermClose * if !v:event.status | exe 'bdelete! '..expand('<abuf>') | endif
]])
Thanks for pointing this out! I've found that this approach works well for me (I've updated the README with this):
vim.keymap.set("n", '<leader>p', function ()
require('detour').Detour() -- open a detour popup
vim.cmd.terminal('top') -- open a terminal buffer
vim.bo.bufhidden = 'delete' -- close the terminal when window closes
vim.cmd.startinsert() -- go into insert mode
vim.api.nvim_create_autocmd({"TermClose"}, {
buffer = vim.api.nvim_get_current_buf(),
callback = function ()
-- This automated keypress skips for you the "[Process exited 0]" message
-- that the embedded terminal shows.
vim.api.nvim_feedkeys('i', 'n', false)
end
})
end)