1

Whenever there are some git merge conflicts we would type git mergetool and git would automatically launch a merge tool for us to merge the conflicts. I have been using vimdiff for a long time as my mergetool, but found it actually not efficient at all as using three-way merging won't provide more information but would occupy the precious screen space.

So I am really interested in using pure vim (not in diff mode) as my git mergetool. But I can't configure it directly since git only accepts certain difftools as git mergetool(opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare emerge vimdiff).

So I am wondering if there is way that I can configure pure vim as my tool to solve conflicts? Note using vim to open and edit the conflicted files directly is not desired here since you would lose a lot of conveniences provided by calling git mergetool, including automatic file opening and automatic git staging.

8
  • If it's "pure vim (not in diff mode)" what would your workflow look like? You could also see e.g. some other questions for customizing.
    – D. Ben Knoble
    Commented May 17, 2018 at 19:04
  • @D.BenKnoble I just merge the conflicts based on the <<<<, ==== and >>>> marks. I think those information is sufficient for us to solve the most conflicts, isn't it? Besides since we have a larger window by using the pure vim, we would have better understanding of the nearby context when solving the conflicts.
    – hzh
    Commented May 17, 2018 at 19:14
  • What do you mean by automatic git staging? Also, i believe all the information you need is in git help mergetool
    – D. Ben Knoble
    Commented May 17, 2018 at 19:22
  • @D.BenKnoble After you solved the conflicts and closed the file, git would automatically add the file you just solved to index and generate a .orig file. This really helps you to know the progress.
    – hzh
    Commented May 17, 2018 at 19:26
  • 1
    Hm. Check the help page then. I think you can configure vim as your tool and use trustStatus or something similar for the staging.
    – D. Ben Knoble
    Commented May 17, 2018 at 19:27

1 Answer 1

2

I think something like this in your ~/.gitconfig file should do what your asking.

[merge] 
    tool = myvimdiff
[mergetool "myvimdiff"]
    cmd = vim "$MERGED"

There are lots of other options for the mergetool besides cmd, search for merge.<tool>. in man git-config (and obviously you can customise cmd how you like it. When merging 4 files are available: $LOCAL, $BASE, $REMOTE, and $MERGED (again look at the documentation for that). You can see how git sets up the default tools here if you want more inspiration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.