From a57a9f10e9e8787fd942a0ebdbfefb0092ccbe65 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Thu, 18 Jul 2024 11:34:11 +0300 Subject: [PATCH] Neovim: add keybinds for gitsigns --- home/.config/nvim/lua/plugins/gitsigns.lua | 50 ++++++++++++++-------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/home/.config/nvim/lua/plugins/gitsigns.lua b/home/.config/nvim/lua/plugins/gitsigns.lua index 6e620bc..72e4e00 100644 --- a/home/.config/nvim/lua/plugins/gitsigns.lua +++ b/home/.config/nvim/lua/plugins/gitsigns.lua @@ -1,22 +1,36 @@ +local k = function(lhs, rhs, opts) + vim.keymap.set("", lhs, rhs, opts) +end + --- @type LazyPluginSpec return { "lewis6991/gitsigns.nvim", - config = true, - lazy = false, - keys = { - { - "[h", - function() - require("gitsigns").prev_hunk() - end, - desc = "Previous hunk", - }, - { - "]h", - function() - require("gitsigns").next_hunk() - end, - desc = "Next hunk", - }, - }, + config = function() + local gs = require("gitsigns") + gs.setup() + + -- Add groups for which-key + require("which-key").add({ + { "g", group = "Git" }, + { "gr", group = "Reset" }, + { "ga", group = "Add" }, + }) + + -- Keybinds + local opts + + -- Hunk navigation + k("[h", gs.prev_hunk, { desc = "Previous hunk" }) + k("[h", gs.next_hunk, { desc = "Next hunk" }) + + -- Hunk actions + opts = { desc = "Hunk" } + k("grh", gs.reset_hunk, opts) + k("gah", gs.stage_hunk, opts) + + -- Buffer actions + opts = { desc = "Buffer" } + k("gab", gs.stage_buffer, opts) + k("grb", gs.reset_buffer, opts) + end, }