mirror of
https://github.com/boxpositron/absolute-vim.git
synced 2026-02-28 19:50:38 +00:00
This commit adds support for the toggleterm plugin in Neovim. It introduces a new Lua file `toggleterm.lua` in the `absolute/after` directory, which configures the toggleterm plugin. It sets up key mappings to open a terminal and toggle the lazygit terminal. The `toggleterm.lua` file imports the `toggleterm` and `Terminal` modules from the toggleterm plugin. It then sets up the toggleterm plugin using the `toggle_term.setup()` function. The `lazygit` terminal is defined using the `Terminal:new()` function. It specifies the command to run (`lazygit`), the directory to run the command in (`git_dir`), and the floating window options. It also defines an `on_open` function to start insert mode and set a key mapping to close the terminal, and an `on_close` function to start insert mode. The `_LAZYGIT_TOGGLE()` function is defined to toggle the `lazygit` terminal. Key mappings are set using the `vim.api.nvim_set_keymap()` function. The `<leader>gl` mapping is set to call the `_LAZYGIT_TOGGLE()` function, and the `<C-`` mapping is set to open a terminal using the `ToggleTerm` command. Additionally, a new Lua file `toggleterm.lua` is added in the `absolute/plugins` directory, which exports the toggleterm plugin configuration. It requires the `absolute.after.toggleterm` module to configure the toggleterm plugin.
35 lines
902 B
Lua
35 lines
902 B
Lua
local toggle_term = require("toggleterm")
|
|
local Terminal = require("toggleterm.terminal").Terminal
|
|
|
|
toggle_term.setup()
|
|
|
|
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>gl", "<cmd>lua _LAZYGIT_TOGGLE()<CR>", opts)
|
|
|
|
opts.desc = "Open a terminal"
|
|
vim.api.nvim_set_keymap("n", "<C-`>", "<cmd>ToggleTerm<CR>", opts)
|