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).
This commit is contained in:
Marty Oehme 2023-08-07 11:30:09 +02:00
parent 596962c4d1
commit 0a3ca9f2b1
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 20 additions and 2 deletions

View file

@ -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", "<localleader>ho", "<Plug>(git-conflict-ours)", { desc = "Conflict use ours" })
vim.keymap.set("n", "<localleader>hO", "<Plug>(git-conflict-theirs)", { desc = "Conflict use theirs" })
vim.keymap.set("n", "<localleader>hm", "<Plug>(git-conflict-both)", { desc = "Conflict use both" })
vim.keymap.set("n", "<localleader>hM", "<Plug>(git-conflict-none)", { desc = "Conflict use none" })
vim.keymap.set("n", "[x", "<Plug>(git-conflict-prev-conflict)", { desc = "Prev git conflict" })
vim.keymap.set("n", "]x", "<Plug>(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 "<Ignore>"
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 "<Ignore>"
end, { expr = true })
end, { expr = true, desc = "Previous git hunk" })
-- Actions
require("which-key").register({ ["<localleader>h"] = { name = "+git" } })