Visual Studio Code: Use Beyond Compare diff tool
Asked Answered
Y

6

38

The default diff tool of Visual Studio Code is nice, but I'd like to replace it with my beloved Beyond Compare.

It's easy to configure in Visual Studio 2017. It's also configured as the git difftool.

I assumed there should be an extension for Beyond Compare, but I couldn't find one. Also google only delivered results concerning the full VS IDE, but nothing to VSC.

Any suggestions?

Yim answered 13/6, 2017 at 13:37 Comment(1)
I came here with the same question. I did find the Compare Folders extension to be useful.Sadick
N
12

Try this extension:

GitDiffer - Visual Studio Marketplace

It works for me on Windows 10, here is my .gitconfig settings

[difftool "sourcetree"]
    cmd = 'C:/Program Files/Beyond Compare 4/BComp.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
    cmd = 'C:/Program Files/Beyond Compare 4/BComp.exe' \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
    trustExitCode = true
[merge]
    tool = sourcetree
[diff]
    guitool = sourcetree
Nancienancy answered 29/9, 2017 at 2:15 Comment(1)
git config --global diff.guitool "'C:/Program Files/Beyond Compare 4/BComp.exe' $LOCAL $REMOTE" does not work, it will ignore the $LOCAL and $REMOTE portions. Any idea of how the command need be written to set the values you specify?Representationalism
S
11

There is a better solution now, the "Compare Helper" extension: https://marketplace.visualstudio.com/items?itemName=keewek.compare-helper

Once installed and configured, you can select files or folders from the explorer and compare them via the context menu. Works like a charm, and configuration is trivial:

  "compareHelper.defaultExternalTools": {
    "folders": "bcompare",
    "images": "bcompare",
    "text": "bcompare"
  },
  "compareHelper.externalTools": [
    {
      "name": "bcompare",
      "path": "C:/Program Files/Beyond Compare 4/BCompare.exe",
      "compares": ["text", "folders", "images"]
    }
  ],

enter image description here

Sulfurous answered 1/7, 2021 at 6:28 Comment(9)
I could not get that extension to work. No matter what I put in the Compare(External) options are always grayed out. Kind of a bummer.Abel
Make sure that you have exactly two files selected in the VScode explorer. @killianSulfurous
and configuration is trivial... well, that piece of code obviously needs to go somewhere, but how exactly is that trivial?Hargis
@bbbbbbbbb the snippet goes into the VS Code settings file. I added a screenshot to my original reply.Sulfurous
Thank you very much! What about the fact that the options in the Compare submenu are both disabled, always and mo matter what you (I) do?Hargis
@bbbbbbbbb As I answered above, as long as two files or folders are selected in the VS explorer, the options are not greyed out, at least for me. If that does not work for you then I'd suggest you raise the issue with the extension authors: github.com/keewek/vscode-compare-helper/issuesSulfurous
But there is no such thing as "two files" in this context. There's a single file which has been modified, and I need to compare it to its previous version. This previous version is available via the source control service in my project, and obviously not on the VS explorer itself. So are you saying that your solution is not designated for source-control type of comparisons?Hargis
"So are you saying that your solution is not designated for source-control type of comparisons?" Yes, the scope of my solution was always to compare files and folders from the explorer, as you can see in my initial answer.Sulfurous
It does not work with "select for compare" and "compare with selected". I wish it worked with that way of selecting 2 files too. But thanks for the extension.Annuity
W
7

The Scooter Software company just released an official VS Code extension, ScooterSoftware.bcompare-vscode.

Weekender answered 3/1 at 15:34 Comment(0)
H
4

I would file an issue/enhancement on Microsoft's Github @ the VSCode repo: https://github.com/Microsoft/vscode

Best case, it's doable and someone there can direct you pretty quick on how to accomplish it; worst case it's added as an enhancement request and added into Code itself in due time.

Huntress answered 13/6, 2017 at 18:1 Comment(2)
Thanks for the hint. I opened a feature request on github.Yim
Until something better comes along for super tight Beyond Compare integration with VSCode, see this work-around: github.com/Microsoft/vscode/issues/28705#issuecomment-318562674Ectoderm
S
2

I came here searching for a solution to use Beyond Compare from within the VS Code sidebar explorer, which is probably not exactly what the OP was after. However, maybe he or others might still find this useful:

There is an extension called "Windows Explorer Context Menu" which adds the option to show the native shell context menu for a selected file or folder in the VS Code explorer.

Once the extension is installed, you can right-click a file or folder, choose Context Menu - Selected and then the desired Beyond Compare operation from the native shell menu.

Unfortunately it does not recognise multiple selected files, so in order to compare two files or folders you have to do this twice, first Select left file/folder for Compare and then Compare (so tbh it's not really easier than just doing a Reveal in Explorer, but at least you can stay inside the VS Code context).

Sulfurous answered 27/8, 2019 at 16:1 Comment(0)
F
0

For VS Code on Mac OS

1. Install the VS Code Compare Helper Extension

2. Install Beyond Compare command line tools

Inside of Beyond Compare install the command line tools from the menu Install Beyond Compare Command Line Tools enter image description here

3. Add the following to your VSCode settings.json

"compareHelper.defaultExternalTools": {
    "folders": "bcompare",
    "images": "bcompare",
    "text": "bcompare"
},
"compareHelper.externalTools": [
    {
        "name": "bcompare",
        "path": "bcompare",
        "compares": [ "text", "folders", "images" ],
        "args": [
            "${FOLDER_ITEM_1}",
            "${FOLDER_ITEM_2}"
        ]
    }
],
Fancie answered 21/11, 2022 at 18:17 Comment(2)
This worked well up until about May 2023, there must have been a VS code update. Now the context menu items are greyed out no matter how many files are selected.Fancie
This is working for me now (Sep 2023). In addition, I can compare working copy to the last version in Git if I go to the file in the Source Control tab, right-click and select "Open Changes with"... "difftool". But the diff display is always the 3-pane "merge" display , not the 2-pane "diff" display and so you can't easily revert sections of the file back to baseline. However it did not work if I included the "args" portion of the json text above in Justin Ohm's answer. Finally, the separate command line tools for BC step seems to be a Mac-only thing?Gebler

© 2022 - 2024 — McMap. All rights reserved.