dotfiles/dot_config/nvim/after/plugin/toggleterm.lua
2026-02-06 09:15:12 +01:00

52 lines
1.3 KiB
Lua

-- English comments only.
local ok, toggleterm = pcall(require, "toggleterm")
if not ok then
return
end
toggleterm.setup({
open_mapping = [[<c-\>]], -- Ctrl + \
direction = "float", -- "horizontal" | "vertical" | "tab" | "float"
close_on_exit = true,
start_in_insert = true,
shade_terminals = true,
float_opts = {
border = "rounded",
},
})
-- Terminal mode keymaps (quality of life)
function _G.set_terminal_keymaps()
local opts = { buffer = 0, silent = true }
-- Exit terminal insert mode
vim.keymap.set("t", "<Esc>", [[<C-\><C-n>]], opts)
-- Navigate windows from terminal
vim.keymap.set("t", "<C-h>", [[<C-\><C-n><C-w>h]], opts)
vim.keymap.set("t", "<C-j>", [[<C-\><C-n><C-w>j]], opts)
vim.keymap.set("t", "<C-k>", [[<C-\><C-n><C-w>k]], opts)
vim.keymap.set("t", "<C-l>", [[<C-\><C-n><C-w>l]], opts)
end
vim.cmd([[autocmd! TermOpen term://* lua set_terminal_keymaps()]])
-- LazyGit terminal
local ok_term, Term = pcall(require, "toggleterm.terminal")
if not ok_term then
return
end
local lazygit = Term.Terminal:new({
cmd = "lazygit",
hidden = true,
direction = "float",
float_opts = { border = "rounded" },
})
function _G.LazygitToggle()
lazygit:toggle()
end
vim.keymap.set("n", "<leader>gg", "<cmd>lua LazygitToggle()<CR>", { silent = true, desc = "LazyGit" })