From 3fe8d4f86daf5ee3caefa191812bf20ce44b94b7 Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Wed, 22 May 2024 09:02:29 +0200 Subject: [PATCH] use toggleterm for lazygit --- lua/plugins/lazygit.lua | 19 ------------------- lua/plugins/toggleterm.lua | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 19 deletions(-) delete mode 100644 lua/plugins/lazygit.lua diff --git a/lua/plugins/lazygit.lua b/lua/plugins/lazygit.lua deleted file mode 100644 index 8faded0..0000000 --- a/lua/plugins/lazygit.lua +++ /dev/null @@ -1,19 +0,0 @@ -return { - 'kdheepak/lazygit.nvim', - cmd = { - 'LazyGit', - 'LazyGitConfig', - 'LazyGitFilter', - 'LazyGitFilterCurrentFile', - 'LazyGit', - }, - keys = { - { - 'g', - function() - require('lazygit').lazygit() - end, - desc = 'LazyGit' - } - } -} diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua index 2a84160..ab28232 100644 --- a/lua/plugins/toggleterm.lua +++ b/lua/plugins/toggleterm.lua @@ -18,7 +18,40 @@ return { }) local Terminal = require('toggleterm.terminal').Terminal + 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', 'close', { noremap = true, silent = true }) + end, + -- function to run on closing the terminal + on_close = function(term) + vim.cmd('startinsert!') + end, + }) + function _lazygit_toggle() + lazygit:toggle() + end + + vim.keymap.set('n', 'g', function() + end, + { noremap = true, silent = true }) end, + keys = { + { + 'g', + function() + _lazygit_toggle() + end, + desc = 'LazyGit' + } + }, cmd = 'ToggleTerm', }