Visual Studio Code - How to easily diff and compare two files

In this post I will share four ways to diff and compare files in Visual Studio Code. All of them are built-in and require no extensions. I have used these methods a lot over the years!

The four ways are:

  • Compare with clipboard
  • Compare with another open tab
  • Compare two local files - Using Compare Selected
  • Compare two local files - Using Select for compare

Let us get started.

1 - Compare with clipboard

A previous great colleague of mine showed me that you can easily compare a file with what you currently have in your clipboard. You have to open up the file you want to compare and copy what it is you want to compare it against. Then you go to the command palette (ctrl + shift + a) under "View": VSCode-Command-palette

You can then search for "compare active file with clipboard":

vscode-compare-file-with-clipboard

Upon hitting enter you will be presented with the differences:

VSCode-compare-with-clipboard-result

I find this approach simple as you often want to compare from sources that are not necessarily local files or that you do not want to save.

2 - Compare with another open tab

You may have two tabs (files) open that you want to compare. To easily do this we will use the command palette again with the command "compare active file with..":

VScode-compare-active-file-with

The result of the above gives you the opportunity to search for files or choose open tabs:

VScode-compare-active-file-with-result

Again we will see the differences in the two compared:

VScode-compare-with-active-file-result-compare

3 - Compare two local files - Using Compare Selected

Maybe you want to compare two files that you have in your Explorer. To easily do this select both by holding shift, right click and use "Compare Selected" like below:

VSCode-Select-For-Compare

The result is a comparison of the two:

VSCode-Compare-Two-Files-Result

4 - Compare two local files - Using Select for compare

Alternatively you can use "Select for compare" on the first file:

VSCode-Select-For-Compare-1

and then "Compare with Selected" on the second:

VScode-Compare-with-selected

The result is a comparison of the two:

VSCode-Compare-Two-Files-Result

That is all

I hope you will find this as helpful as I have over the years! Let me know in the comments what you think!