Skip to content

Instantly share code, notes, and snippets.

@Pagliacii
Last active May 5, 2024 21:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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