From 15246a74ab004f81cacec17ab4450d0be88d0b6d Mon Sep 17 00:00:00 2001 From: David Ibia Date: Fri, 16 Feb 2024 14:13:23 +0100 Subject: [PATCH] feat(toggleterm.lua): add support for toggleterm plugin to open a terminal and lazygit 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 `gl` mapping is set to call the `_LAZYGIT_TOGGLE()` function, and the `close", 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", "gl", "lua _LAZYGIT_TOGGLE()", opts) + +opts.desc = "Open a terminal" +vim.api.nvim_set_keymap("n", "", "ToggleTerm", opts) diff --git a/lua/absolute/plugins/toggleterm.lua b/lua/absolute/plugins/toggleterm.lua new file mode 100644 index 0000000..9748efc --- /dev/null +++ b/lua/absolute/plugins/toggleterm.lua @@ -0,0 +1,7 @@ +return { + "akinsho/toggleterm.nvim", + version = "*", + config = function() + require("absolute.after.toggleterm") + end, +}