VS Code: How to Compare Two Files (Find the Difference)

Last updated on September 25, 2022 A Goodman Loading... Post a comment

This concise and straightforward article shows you a couple of different ways to compare two files using VS Code (Visual Studio Code). The first approach is to use your mouse, and the second one is to use the command line.

Using Your Mouse

1. Hold the Ctrl key (if you’re using Windows) or the Command key (if you’re on a Mac) and select the two files you want to compare with your mouse, right-click, then select “Compare Selected” from the drop-down menu.

2. The difference will be highlighted as follows:

The animated GIF below clearly tells what I mean:

Using Command Line

The command that can be used to check the diff between two files:

code --diff [path to file 1] [path to file 2]

When you run the command above, you may run into this error:

command not found: code

Solution: Open Command Palette (press “Command” + “Shift” + “P” on Mac and “Ctrl” + “Shift” + “P” on Windows), search for “install code” and select “Shell Command: Install ‘code’ command in PATH”:

And you will see this:


code --diff ./lib/main.dart ./lib/draft.dart

The result:


We’ve gone through two different ways to check the difference between two files by using VS Code. If you’d like to explore more about this excellent IDE, take a look at the following articles:

You can also check our VS Code topic page for the latest guides, tips, and tricks.

Notify of
Inline Feedbacks
View all comments

Related Articles