Skip to content

Instantly share code, notes, and snippets.

@Pagliacii
Last active October 28, 2024 03:19
Show Gist options
  • Save Pagliacii/8fcb4dc64937305c19df9bb3137e4cad to your computer and use it in GitHub Desktop.
Save Pagliacii/8fcb4dc64937305c19df9bb3137e4cad to your computer and use it in GitHub Desktop.
Using Neovim as a merge tool

git

Using diffview.nvim

# ~/.gitconfig
[merge]
  tool = diffview
[mergetool]
  prompt = false
  keepBackup = false
[mergetool "diffview"]
  cmd = nvim -n -c "DiffviewOpen" "$MERGE"

Using git default nvimdiff

# ~/.gitconfig
[merge]
  tool = nvimdiff
[mergetool]
  prompt = false
  keepBackup = false
[mergetool "nvimdiff"]
  layout = "LOCAL,BASE,REMOTE / MERGED"

Usage

$ git merge other-branch
# oops, conflicts!
$ git mergetool

hg

Using diffview.nvim

# ~/.hgrc
[ui]
merge = internal:merge
[extensions]
purge =
[alias]
mergetool = !nvim -n -c "DiffviewOpen" && hg resolve --mark && hg purge -I **/*.orig --all

Using neovim diff-mode

# ~/.hgrc
[ui]
merge = nvimdiff
[extensions]
purge =
[hooks]
post-merge = hg purge -I **/*.orig --all
[merge-tools]
nvimdiff.executable = nvim
nvimdiff.args = -d $output -M $local $base $other -c "wincmd J" -c "set modifiable" -c "set write" -c "nnoremap co :diffget 2<cr>" -c "nnoremap ct :diffget 4<cr>"
nvimdiff.premerge = keep
nvimdiff.check = conflicts

Usage

$ hg merge other-branch
# oops, conflicts!
# If using diff-mode, the neovim will be opened automatically after conflicts occurred
$ hg mergetool  # for diffview.nvim

Refs

  1. diff-mode
  2. sindrets/diffview.nvim
  3. mergetools/vimdiff.txt
  4. hgrc merge-tools
  5. MergingWithVim
  6. How to use git mergetool to resolve conflicts in Vim / NeoVim
  7. Neovim As Git Mergetool
  8. Using Vim or NeoVim as a Git mergetool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment