I would like to configure a git mergetool setting with vanilla Vim 8.2 to open up three tabs:

  • Tab A: The merged file (the file that is supposed to be edited)
  • Tab B: Diff between base and local file
  • Tab C: Diff between base and remote file

Now, I am trying to achieve this from the command line, but the moment Vim opens a new tab it will not open up a new file in the new tab. It almost looks like the tabs feature does not work well with command line arguments:

[mergetool "vimdifftabs"]
  cmd = vim -f -c "e $MERGED" -c "tabe $BASE" -c "diffs $LOCAL" -c "tabe $BASE" -c "diffs $REMOTE"

Looks like even this does not work:

[mergetool "vimdifftabs"]
  cmd = vim -f -c "e $MERGED" -c "tabe $BASE"

The second tab is empty, no file opened there. When I try to explicitly create the tab first and then edit the file:

[mergetool "vimdifftabs"]
  cmd = vim -f -c "e $MERGED" -c tabnew -c "e $BASE"

Vim says: No filename. But I tested that git is passing the base filename correctly in that variable. I am not getting it.

  • For the base case of simply opening (real) files in tabs there's the command line flag -p which will open each specified file in its own tab (e.g. vim -p foo.txt bar.txt will start with foo.txt in one tab and bar.txt in another). Any luck with that?
    – B Layer
    Nov 25, 2021 at 11:38
  • BTW, do any of the things you tried work when you run them directly from the command line rather than through any git stuff? (Just substituting actual filenames for the variables to test it and if that works try it with temp variables that point to those files.)
    – B Layer
    Nov 25, 2021 at 11:44
  • 1
    Great point, it was escaping in the gitconfig! Thanks.
    – lzap
    Nov 25, 2021 at 12:10

1 Answer 1


Found it, I had to escape quotes in the gitconfig! Here is the solution:

[mergetool "vimdifftabs"]
  cmd = vim -f -c \"tabe $BASE\" -c \"diffsplit $LOCAL\" -c \"tabe $BASE\" -c \"diffsplit $REMOTE\" \"$MERGED\"

Here is a slightly advanced version which highlights conflicts and goes to the top of the first (tab) file:

[mergetool "vimdifftabs"]
  cmd = vim -f -c \"tabe $BASE\" -c \"diffsplit $LOCAL\" -c \"tabe $BASE\" -c \"diffsplit $REMOTE\" -c tabfirst -c \"/=======\" -c \"normal gg\" \"$MERGED\"


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.