meJustAndrew
meJustAndrew

Reputation: 6603

Is there a way to switch the compare direction with VS Code?

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.

Upvotes: 21

Views: 7561

Answers (3)

eternaldebugging
eternaldebugging

Reputation: 129

This is a thing now as of 1.86, see the accepted answer

2021:

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.

Upvotes: 12

starball
starball

Reputation: 50024

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.

Upvotes: 17

firstpostcommenter
firstpostcommenter

Reputation: 2911

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.

Upvotes: 8

Related Questions