add term toggle

main
Dominik Madarász 2024-11-10 17:33:13 +01:00
parent 70efa980c0
commit 9500030f56
1 changed files with 14 additions and 2 deletions

View File

@ -19,11 +19,23 @@ vim.keymap.set("n", "<C-m>", "<C-6>")
vim.keymap.set("t", "<Esc>", "<C-\\><C-n>", { noremap = true, silent = true })
-- vim.keymap.set("n", "<leader>;", ":vsplit term://left<CR><A-Right><CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<C-k>", function ()
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")
else
-- Open a new terminal at the bottom 25% of the screen
vim.cmd("belowright split | resize " .. math.floor(vim.o.lines * 0.25))
vim.cmd("terminal")
vim.cmd("startinsert")
end)
end
end
vim.keymap.set("n", "<C-o>", toggleTerminal, { noremap = true, silent = true })
vim.keymap.set("v", "<C-o>", toggleTerminal, { noremap = true, silent = true })
vim.keymap.set("i", "<C-o>", toggleTerminal, { noremap = true, silent = true })
vim.keymap.set("t", "<C-o>", toggleTerminal, { noremap = true, silent = true })
-- Terminal mode mappings (Alt + hjkl and Alt + Arrow Keys)
vim.api.nvim_set_keymap('t', '<A-h>', '<C-\\><C-N><C-w>h', { noremap = true, silent = true })