Files
absolute-vim/lua/absolute/after/toggleterm.lua
David Ibia 55edad9ed6 fix(toggleterm.lua): change key mapping for opening lazygit from "<leader>gl" to "<leader>gs" to avoid conflicts with other mappings
feat(toggleterm.lua): set toggleterm direction to "float" to make the terminal window float instead of splitting the current window
2024-02-16 22:59:57 +01:00

37 lines
930 B
Lua

local toggle_term = require("toggleterm")
local Terminal = require("toggleterm.terminal").Terminal
toggle_term.setup({
direction = "float",
})
local opts = { noremap = true, silent = true }
local lazygit = Terminal:new({
cmd = "lazygit",
dir = "git_dir",
direction = "float",
float_opts = {
border = "double",
},
-- function to run on opening the terminal
on_open = function(term)
vim.cmd("startinsert!")
vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "<cmd>close<CR>", opts)
end,
-- function to run on closing the terminal
on_close = function(term)
vim.cmd("startinsert!")
end,
})
function _LAZYGIT_TOGGLE()
lazygit:toggle()
end
opts.desc = "Open lazygit"
vim.api.nvim_set_keymap("n", "<leader>gs", "<cmd>lua _LAZYGIT_TOGGLE()<CR>", opts)
opts.desc = "Open a terminal"
vim.api.nvim_set_keymap("n", "<C-`>", "<cmd>ToggleTerm<CR>", opts)