Resolve merge conflicts like a pro with nvim
(taken from diffview.nvim repository)
Over the years, I’ve gone through so many merge tools - kdiff3, meld, beyond compare, Kaleidoscope. Nvim being my editor of choice, fortunately, has a rich ecosystem of plugins where I can set up an uber merge workflow using diffview.nvim
and avoid using external tools altogether.
Getting started
Make sure you have the latest nvim installed (I have v0.10.4). Although I use lazyvim as the base to provide the basic (and some advanced) editor features, I have to set recourse to diffview.nvim to ease my merging process.
The first and only step is to edit the .gitconfig file to add these options
[merge]
tool =nvim-diffview
[mergetool "nvim-diffview"]
cmd = "nvim -c 'DiffviewOpen'"
prompt = false
Et voila. Now each merge conflict that opens automatically in a diff view with simple keybindings, a brief overview of which is provided below:
[x , ]x
jump to different previous / next conflict marker<leader>co
: Choose the OURS version of the conflict.<leader>ct
: Choose the THEIRS version of the conflict.<leader>cb
: Choose the BASE version of the conflict.<leader>ca
: Choose all versions of the conflict (effectively just deletes the markers, leaving all the content).dx
: Choose none of the versions of the conflict (delete the conflict region).
As usual, you can just :h diffview
anytime you need to refer to some config / keybinding.
You can also check out my full .gitconfig
here and my full neovim config
Comments