diff --git a/lua/zak/remap.lua b/lua/zak/remap.lua index b49cf44..c77d341 100644 --- a/lua/zak/remap.lua +++ b/lua/zak/remap.lua @@ -19,17 +19,28 @@ vim.keymap.set("n", "", "") vim.keymap.set("t", "", "", { noremap = true, silent = true }) -- vim.keymap.set("n", ";", ":vsplit term://left", { noremap = true, silent = true }) +local term_buf = nil + + function toggleTerminal() - -- Check if the current buffer is a terminal - if vim.bo.buftype == "terminal" then - -- Close the terminal if we're already in one - vim.cmd("close") + -- If we already have a terminal buffer and it's hidden, reopen it + if term_buf and vim.api.nvim_buf_is_valid(term_buf) then + -- If the terminal is open in the current window, hide it + if vim.api.nvim_get_current_buf() == term_buf then + vim.cmd("close") + else + -- Otherwise, open the terminal buffer in a split at the bottom + vim.cmd("belowright split | resize " .. math.floor(vim.o.lines * 0.25)) + vim.api.nvim_set_current_buf(term_buf) + vim.cmd("startinsert") + end else - -- Open a new terminal at the bottom 25% of the screen + -- If no terminal buffer exists, create a new one vim.cmd("belowright split | resize " .. math.floor(vim.o.lines * 0.25)) vim.cmd("terminal") vim.cmd("startinsert") - end + term_buf = vim.api.nvim_get_current_buf() -- Store the terminal buffer ID + end -- Check if the current buffer is a terminal end vim.keymap.set("n", "", toggleTerminal, { noremap = true, silent = true }) diff --git a/lua/zak/session.lua b/lua/zak/session.lua index f41be32..d3c51b5 100644 --- a/lua/zak/session.lua +++ b/lua/zak/session.lua @@ -1,7 +1,7 @@ -- Define a custom shortcut that runs when Neovim starts vim.api.nvim_create_autocmd("UIEnter", { callback = function() - vim.cmd("vsplit | terminal") + vim.cmd("vsplit | Explore") vim.cmd("wincmd l") vim.cmd("Explore") end,