From 0a3ca9f2b148c53ceba1e9a6456996517797fea3 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 7 Aug 2023 11:30:09 +0200 Subject: [PATCH] nvim: Add git conflict resolution mappings Added simple merge conflict highlighting and resolution through git-conflict.nvim plugin. Allows moving to the next/prev conflict with ]x or [x respectively, then resolving the conflict currently hovered by using ours/theirs/ both/or neither of the offered options (with `ho/hO/hm/hM` respectively). --- nvim/.config/nvim/lazy-lock.json | 1 + nvim/.config/nvim/lua/plugins/git.lua | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 227ff51..38e1e12 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -27,6 +27,7 @@ "fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" }, "friendly-snippets": { "branch": "main", "commit": "ea84a710262cb2c286d439070bad37d36fd3db25" }, "fwatch.nvim": { "branch": "main", "commit": "a691f7349dc66285cd75a1a698dd28bca45f2bf8" }, + "git-conflict.nvim": { "branch": "main", "commit": "8d962d83cae924a314965f738ed1e05a4000d682" }, "gitsigns.nvim": { "branch": "main", "commit": "bb808fc7376ed7bac0fbe8f47b83d4bf01738167" }, "headlines.nvim": { "branch": "master", "commit": "ddef41b2664f0ce25fe76520d708e2dc9dfebd70" }, "jupyter-kernel.nvim": { "branch": "main", "commit": "5b409598033884a3d819e2a3bcd1fe340bc8d783" }, diff --git a/nvim/.config/nvim/lua/plugins/git.lua b/nvim/.config/nvim/lua/plugins/git.lua index 165e5d2..21e7deb 100644 --- a/nvim/.config/nvim/lua/plugins/git.lua +++ b/nvim/.config/nvim/lua/plugins/git.lua @@ -1,4 +1,21 @@ return { + { + "akinsho/git-conflict.nvim", + event = "VeryLazy", + config = function() + require("git-conflict").setup({ + default_mappings = false, + disable_diagnostics = true, + }) + vim.keymap.set("n", "ho", "(git-conflict-ours)", { desc = "Conflict use ours" }) + vim.keymap.set("n", "hO", "(git-conflict-theirs)", { desc = "Conflict use theirs" }) + vim.keymap.set("n", "hm", "(git-conflict-both)", { desc = "Conflict use both" }) + vim.keymap.set("n", "hM", "(git-conflict-none)", { desc = "Conflict use none" }) + vim.keymap.set("n", "[x", "(git-conflict-prev-conflict)", { desc = "Prev git conflict" }) + vim.keymap.set("n", "]x", "(git-conflict-next-conflict)", { desc = "Next git conflict" }) + end, + lazy = false, -- TODO needs to be force refreshed in lazy loaded mode unfortunately + }, { "lewis6991/gitsigns.nvim", -- show vcs changes on left-hand gutter event = "VeryLazy", @@ -24,7 +41,7 @@ return { gs.next_hunk() end) return "" - end, { expr = true }) + end, { expr = true, desc = "Next git hunk" }) map("n", "[h", function() if vim.wo.diff then @@ -34,7 +51,7 @@ return { gs.prev_hunk() end) return "" - end, { expr = true }) + end, { expr = true, desc = "Previous git hunk" }) -- Actions require("which-key").register({ ["h"] = { name = "+git" } })