How to configure git mergetool properly for neovim?

3.7k Views Asked by At

I'm trying to use neovim as git mergetool but it is not working as expected or as I understood from the documentation.

Here's my .gitconfig:

[user]
    name = Augusto
[pull]
    rebase = true
[diff]
    tool = nvimdiff
    guitool = nvimdiff
[merge]
    tool = nvimdiff
    conflictstyle = diff3
[mergetool]
    keepBackup = false
    trustExitCode = false
    prompt = true
[difftool]
    prompt = false
[commit]
    gpgsign = true
[core]
    editor = nvim
    pager = bat
[mergetool "nvimdiff"]
    layout = LOCAL,MERGED,REMOTE

When I run git mergetool, it opens NeoVim as expected, but not with the correct layout. It always opens with the default but not with all the "files" it should open.

Instead of

------------------------------------------
|             |           |              |
|   LOCAL     |   BASE    |   REMOTE     |
|             |           |              |
------------------------------------------
|                                        |
|                MERGED                  |
|                                        |
------------------------------------------

It is opening like this

------------------------------------------
|             |           |              |
|   LOCAL     |   LOCAL   |   MERGED     |
|             |           |              |
------------------------------------------
|                                        |
|                LOCAL                   |
|                                        |
------------------------------------------

Command outputs:

git config mergetool.nvimdiff.layout
LOCAL,MERGED,REMOTE

git config merge.tool
nvimdiff
1

There are 1 best solutions below

7
silentfrost On

I had the same issue where the layout wasn't being applied when using the nvimdiff. It turns out that you need to use vimdiff instead of nvimdiff when configuring the layout. The docs git-mergetool detail that vim and nvim use the same layout config.

[mergetool "vimdiff"]
    layout = LOCAL,MERGED,REMOTE