From f34f2fc706e2fad1f336043ff064ef7f52a201d2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 3 Mar 2022 22:15:26 +0100 Subject: [PATCH] home: vim: configure 'gitsigns' And remove some unused mappings, or adapt them to 'gitsigns'. --- home/vim/after/plugin/mappings/git.vim | 2 - home/vim/plugin/settings/gitsigns.vim | 54 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 home/vim/plugin/settings/gitsigns.vim diff --git a/home/vim/after/plugin/mappings/git.vim b/home/vim/after/plugin/mappings/git.vim index 677abd0..bb8b194 100644 --- a/home/vim/after/plugin/mappings/git.vim +++ b/home/vim/after/plugin/mappings/git.vim @@ -9,10 +9,8 @@ local keys = { }, ["g"] = { name = "Git", - d = { "Gdiffsplit", "Current buffer diff" }, l = { ":spT:Gllog --follow -- %:p", "Current buffer log" }, m = { "(git-messenger)", "Current line blame" }, - s = { "Gstatus", "Status" }, }, } diff --git a/home/vim/plugin/settings/gitsigns.vim b/home/vim/plugin/settings/gitsigns.vim new file mode 100644 index 0000000..7804f3e --- /dev/null +++ b/home/vim/plugin/settings/gitsigns.vim @@ -0,0 +1,54 @@ +lua << EOF +local gitsigns = require('gitsigns') + +gitsigns.setup({ + -- I dislike the full-green sign column when this happens + attach_to_untracked = false, + + current_line_blame_opts = { + -- Show the blame quickly + delay = 100, + }, + + on_attach = function(bufnr) + local wk = require("which-key") + + local keys = { + -- Navigation + ["[c"] = { "&diff ? '[c' : 'Gitsigns prev_hunk'", "Previous hunk/diff", expr = true }, + ["]c"] = { "&diff ? ']c' : 'Gitsigns next_hunk'", "Next hunk/diff", expr = true }, + + + -- Commands + ["g"] = { + name = "Git", + -- Actions + b = { gitsigns.toggle_current_line_blame, "Toggle blame virtual text" }, + d = { gitsigns.diffthis, "Diff buffer" }, + D = { function() gitsigns.diffthis("~") end, "Diff buffer against last commit" }, + h = { gitsigns.toggle_deleted, "Show deleted hunks" }, + p = { gitsigns.preview_hunk, "Preview hunk" }, + r = { gitsigns.reset_hunk, "Revert hunk" }, + R = { gitsigns.reset_buffer, "Revert buffer" }, + s = { gitsigns.stage_hunk, "Stage hunk" }, + S = { gitsigns.stage_buffer, "Stage buffer" }, + u = { gitsigns.undo_stage_hunk, "Undo stage hunk" }, + ["["] = { gitsigns.prev_hunk, "Previous hunk" }, + ["]"] = { gitsigns.next_hunk, "Next hunk" }, + }, + } + + local objects = { + ["ih"] = { gitsigns.select_hunk, "Git hunk" }, + } + + local visual = { + ["ih"] = { gitsigns.select_hunk, "Git hunk" }, + } + + wk.register(keys, { buffer = bufnr }) + wk.register(objects, { mode = "o" }) + wk.register(visual, { mode = "x" }) + end, +}) +EOF