fix(nvim): ensure toggleterm exits when toggled

This commit is contained in:
Price Hiller 2023-09-07 22:51:25 -05:00
parent 0a2c4f9d64
commit de48802722
No known key found for this signature in database

View File

@ -2,7 +2,28 @@ return {
{
"akinsho/toggleterm.nvim",
keys = {
{ "<leader><leader>", "<cmd>ToggleTerm<CR>", desc = "ToggleTerm: Toggle" },
{
"<leader><leader>",
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,