diff --git a/dots/.config/nvim/lua/plugins/configs/toggleterm.lua b/dots/.config/nvim/lua/plugins/configs/toggleterm.lua index 8511c7e0..766da489 100644 --- a/dots/.config/nvim/lua/plugins/configs/toggleterm.lua +++ b/dots/.config/nvim/lua/plugins/configs/toggleterm.lua @@ -2,7 +2,28 @@ return { { "akinsho/toggleterm.nvim", keys = { - { "", "ToggleTerm", desc = "ToggleTerm: Toggle" }, + { + "", + function() + local mode = vim.fn.mode(1) + local curr_buffer = vim.api.nvim_buf_get_name(0) + local toggleterm_match = function(buf_name) + return buf_name:find("toggleterm#", 1, true) + end + if toggleterm_match(curr_buffer) then + -- Try to exit with toggleterm + vim.cmd.ToggleTerm() + + -- We didn't successfully exit, use `q` to do so. + if toggleterm_match(vim.api.nvim_buf_get_name(0)) then + vim.cmd(":q") + end + else + vim.cmd.ToggleTerm() + end + end, + desc = "ToggleTerm: Toggle" + }, }, opts = { start_in_insert = false,