17

I use VSCode as my default tool to compare files (git changes and others) and I sometimes I need to see the differences in the other way than I have them opened in the viewer.

For example, suppose I have the following comparison

enter image description here

And I want them to be shown the other way around like Doc2 <-> Doc1

enter image description here

Is there a way to easily do this without closing the current comparison and opening a new one in the other order?

Anything would work, it can be a shortcut (the ideal option) or a button that I can press which I am currently missing.

3 Answers 3

12

You currently can't do this (version 1.54), but it has been suggested here on the github.

There is an extension for this here.

1
  • It is not what I wanted to find out, but it is indeed what I was looking for. Thanks a lot for the answer, hope it gets implemented soon Commented Mar 11, 2021 at 17:00
10

This is supported in VS Code 1.86. You can use Compare: Swap Left and Right Editor Side in the command palette.

If you want to bind it to a keyboard shortcut, the command's ID is workbench.action.compareEditor.swapSides. See also the isInDiffEditor context key.

If you're interested in the history, see Allow to swap left and right hand side in diff editor #20958.

3
  • In version 1.88 the described command Compare: Swap Left and Right Editor Side seems to disappear?? Commented Apr 12 at 10:01
  • @PetrBodnár cannot repro. it appears for me when in a comparison tab.
    – starball
    Commented Apr 12 at 10:10
  • confirmed. I have overlooked this feature only applies to explicitly selected files comparison. So it isn't available e.g. when diffing outgoing changes within a Git project. Commented Apr 12 at 14:29
7

There is no option yet to swap files but for other readers it would be helpful to know that the order in which you selected the files in the Explorer matters.

Lets say there are 2 files "file1" and "file2"

If you select file1 first and then file2 and then right click -> compare selected then file1 is on the left and file2 is on the right.

If you select file2 first and then file1 and then right click -> compare selected then file2 is on the left and file1 is on the right.

3
  • 1
    Too bad there isn't something as simple as that built it. But, this answer helps me know that order of file selection (click) matters Commented Mar 9, 2023 at 17:49
  • This stopped working at some point, for instance in version: 1.84.0 it no longer works Commented Dec 6, 2023 at 8:24
  • 1
    In version 1.90.2, I find that the direction of the diff is based on the order of the two selected tabs in the tab bar. I can swap it by re-ordering the two tabs, then opening the comparison. Commented Jul 24 at 23:57

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.