From 3fae9d88c524db10b4c370cda94abad6cc5e5182 Mon Sep 17 00:00:00 2001 From: "Jacob E. Tuz Poot" Date: Mon, 26 Sep 2022 18:29:39 -0500 Subject: [PATCH] feat: add buffer mapping for gitsigns --- lua/core/mappings.lua | 133 +++++++++++++++++++++++++++++++++ lua/plugins/configs/others.lua | 4 + 2 files changed, 137 insertions(+) diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 3d9df51..2c83041 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -404,4 +404,137 @@ M.blankline = { }, } +M.gitsigns = { + plugin = true, + + n = { + -- Navigation + ["]c"] = { + function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() + require("gitsigns").next_hunk() + end) + return "" + end, + "Jump to next hunk", + opts = { expr = true }, + }, + ["[c"] = { + function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() + require("gitsigns").prev_hunk() + end) + return "" + end, + "Jump to prev hunk", + opts = { expr = true }, + }, + + -- Actions + ["hs"] = { + function() + require("gitsigns").stage_hunk() + end, + "Stage hunk", + }, + ["hr"] = { + function() + require("gitsigns").reset_hunk() + end, + "Reset hunk", + }, + ["hS"] = { + function() + require("gitsigns").stage_buffer() + end, + "Stage buffer", + }, + ["hu"] = { + function() + require("gitsigns").undo_stage_hunk() + end, + "Undo stage hunk", + }, + ["hR"] = { + function() + require("gitsigns").reset_buffer() + end, + "Reset buffer", + }, + ["hp"] = { + function() + require("gitsigns").preview_hunk() + end, + "Preview hunk", + }, + ["hb"] = { + function() + package.loaded.gitsigns.blame_line { full = true } + end, + "Blame line", + }, + ["tb"] = { + function() + require("gitsigns").toggle_current_line_blame() + end, + "Toggle current line blame", + }, + ["td"] = { + function() + require("gitsigns").toggle_deleted() + end, + "Toggle deleted", + }, + ["hd"] = { + function() + require("gitsigns").diffthis() + end, + "Diff against the index", + }, + ["hD"] = { + function() + require("gitsigns").diffthis "~" + end, + "Diff against the last commit", + }, + }, + v = { + -- Actions + ["hs"] = { + function() + require("gitsigns").stage_hunk() + end, + "Stage hunk", + }, + ["hr"] = { + function () + require("gitsigns").reset_hunk() + end, + "Reset hunk", + }, + }, + x = { + ["ih"] = { + function () + require("gitsigns").select_hunk() + end, + "Reset hunk", + }, + }, + o = { + ["ih"] = { + function () + require("gitsigns").select_hunk() + end, + "Reset hunk", + }, + }, +} + return M diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 462c44b..4b7508a 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -1,6 +1,7 @@ local M = {} local load_override = require("core.utils").load_override +local utils = require "core.utils" M.autopairs = function() local present1, autopairs = pcall(require, "nvim-autopairs") @@ -145,6 +146,9 @@ M.gitsigns = function() topdelete = { hl = "DiffDelete", text = "‾", numhl = "GitSignsDeleteNr" }, changedelete = { hl = "DiffChangeDelete", text = "~", numhl = "GitSignsChangeNr" }, }, + on_attach = function (bufnr) + utils.load_mappings("gitsigns", { buffer = bufnr }) + end } options = load_override(options, "lewis6991/gitsigns.nvim")