Compare files · VS Code

How to Compare Two Files in VS Code

VS Code has a full diff viewer built in; no extension is needed. There are four ways to open it depending on where the two files are.

From the Explorer: Select for Compare

Right-click the first file and choose Select for Compare, then right-click the second and choose Compare with Selected. Faster: hold Ctrl (Cmd on macOS), click both files, right-click the selection and choose Compare Selected. The diff opens side by side with changed lines highlighted and changed characters emphasised inside them.

Compare with the clipboard or the saved version

Open the command palette (Ctrl+Shift+P) and type File: Compare Active File With Clipboard to diff what you copied against the open file, or File: Compare Active File with Saved to see your unsaved changes. Both are quick ways to check a paste from a ticket or a colleague before you keep it.

Ctrl+Shift+P → File: Compare Active File With…
Ctrl+Shift+P → File: Compare Active File With Clipboard
Ctrl+Shift+P → File: Compare Active File with Saved

From the terminal: code --diff

The command-line launcher opens a diff directly, which is handy from a shell or a script.

$ code --diff app.conf app.conf.new

Reading and navigating the diff

F7 and Shift+F7 jump to the next and previous change (the arrows in the editor title bar do the same). The toggle in the title bar switches between side-by-side and inline views, and the setting diffEditor.ignoreTrimWhitespace hides whitespace-only differences. Changes can be copied from one side to the other with the arrow gutter buttons.

Git changes and folder comparison

The Source Control view opens the same diff viewer for any modified file against the last commit. To compare two folders, install the Compare Folders extension; VS Code itself only diffs files. For a quick look at two texts that are not saved anywhere, the online diff checker below takes a paste on each side.

Compare two texts online Paste both versions. Runs in your browser, nothing is uploaded.

FAQ

Can VS Code compare two files that are not in the workspace?

Yes. Use code --diff path1 path2 from a terminal, or open both files (File › Open) and use Compare Active File With… from the command palette.

How do I ignore whitespace in the VS Code diff?

Enable Diff Editor: Ignore Trim Whitespace in settings (diffEditor.ignoreTrimWhitespace), or click the whitespace toggle in the diff editor title bar.

How do I compare two folders in VS Code?

Install the Compare Folders extension. The built-in diff viewer compares files only.