VS Code

How to Compare Two Files in VS Code (Built-In Diff, No Extension)

How to Compare Two Files in VS Code (Built-In Diff, No Extension)

Right-click the first file in the Explorer view and choose Select for Compare. Then right-click the second file and choose Compare with Selected. The diff opens in a new tab.

From a terminal, code --diff followed by two file paths lands in the same place. Unsaved editors, clipboard text and Git revisions can be compared too, with no extension installed.

Whitespace is the usual catch. VS Code ships diffEditor.ignoreTrimWhitespace as true, so changes in leading or trailing whitespace stay hidden, and two files that differ only in indentation look identical until you switch the setting to false.

How do you compare two files in VSCode?

In the Explorer view, right-click the first file and pick Select for Compare. Right-click the second and pick Compare with Selected. A diff tab opens with both files side by side and every difference highlighted.

The Command Palette and the code --diff command end up in the same editor. Which one is fastest depends on where your hands already are.

Explorer method

This is the route most people learn first. Both files have to be saved on disk and sit inside the open workspace.

  1. Open the folder that holds both files so they show up in the Explorer view (Ctrl+Shift+E on Windows and Linux).
  2. Right-click the first file and select Select for Compare.
  3. Right-click the second file and select Compare with Selected.
  4. The diff opens in a new tab, first file on the left and second on the right.

The right pane is editable, so you can fix a difference on the spot without leaving the diff.

Command Palette method

Start with the first file open as the active editor.

  1. Press Ctrl+Shift+P (Cmd+Shift+P on macOS) and run File: Compare Active File With…
  2. Pick the second file from the list.

This beats right-clicking when the Explorer is hidden or the folder tree is deep. Typing “compare” in the palette gets you to the command in a few keystrokes.

The VS Code editing documentation (Microsoft, current as of November 2026) lists this command first among the active-file comparisons.

Terminal method

code --diff <file1> <file2>

The VS Code command-line reference gives the syntax as -d or --diff followed by two file paths. It runs the same way from the integrated terminal or an external shell.

If the shell says code is not found, macOS users need to run the Command Palette command that installs the code command in PATH. The Windows and Linux installers normally add it already, and a manual PATH entry fixes whatever is left.

That same fix applies when you want to open VSCode from the terminal for any other job.

How to read the diff editor and move between changes

YouTube player

The left pane holds the original text, and removed lines are shaded red there. The right pane holds the modified text, with added lines in green. Inside a changed line, a darker highlight picks out the exact characters that differ, and a +/- marker sits beside the line as well (diffEditor.renderIndicators, on by default).

Side-by-side or inline

Side-by-side is the default, because diffEditor.renderSideBySide is true. Set it to false and every change stacks into one column.

Narrow editors switch on their own. Since the August 2023 release (1.82), VS Code drops to inline view when the editor is too narrow and restores the split layout once there is room again, per Microsoft’s 1.82 release notes.

Setting diffEditor.useInlineViewWhenSpaceIsLimited to false turns that behavior off.

Jumping between changes

Alt+F5 (Option+F5 on macOS) jumps to the next change, and Shift+Alt+F5 goes back to the previous one. The Diff Editor: Switch Side command moves the cursor from one pane to the other without touching the mouse.

On a 2,000-line file with three edits, these shortcuts beat scrolling every time.

Editing and reverting

VS Code 1.88 (March 2024) added a separate gutter for Stage and Revert controls in the diff editor, according to Microsoft’s release notes. Select part of a change and the controls act only on the selected characters. If the gutter gets in your way, diffEditor.renderGutterMenu set to false hides it.

Since 1.106 (October 2025), text on deleted lines can also be selected and copied in the inline diff view.

Reverting edits the modified side only. Save the file to keep the result.

Which diff editor settings speed up a comparison?

Whitespace handling and collapsing unchanged lines do most of the work. Move detection is more situational. Each one changes what the diff editor shows, and you can set them once and forget about them.

Recent builds ship with the defaults below, and Preferences: Open Default Settings (JSON) will confirm what yours has.

  • diffEditor.renderSideBySide is true
  • diffEditor.renderSideBySideInlineBreakpoint sits at 900 pixels
  • diffEditor.ignoreTrimWhitespace is true
  • diffEditor.hideUnchangedRegions.enabled is false, with 3 context lines
  • diffEditor.experimental.showMoves is false

Whitespace changes

Leave it on for code review. Turn it off for Makefiles, and for anything in YAML or Python.

With ignoreTrimWhitespace set to true, changes in leading or trailing whitespace are hidden. Two files that differ only in indentation then look identical, which is exactly wrong when indentation is syntax.

Unchanged regions

Microsoft’s 1.82 release notes (August 2023) document diffEditor.hideUnchangedRegions.enabled, along with a map icon in the editor context menu that toggles the same behavior.

With it on, every stretch of identical lines collapses and 3 lines of context stay around each change by default. You stop scrolling past pages of unchanged code, which pays off on long files with a handful of edits.

Moved code

The 1.82 notes describe showMoves as detecting code blocks that moved to a different location in the same file. Without it, a relocated function shows up as one deletion and one addition.

Turn it on after refactors that reorder functions.

Where to set them

Open the settings file with Preferences: Open User Settings (JSON), or follow this guide to open the settings.json file from other routes.

{
"diffEditor.ignoreTrimWhitespace": false,
"diffEditor.hideUnchangedRegions.enabled": true,
"diffEditor.experimental.showMoves": true
}

User settings apply everywhere. Workspace settings live in a .vscode folder at the project root, can be shared through version control, and override user settings, per the VS Code settings documentation.

How to compare unsaved files, clipboard text and selections

The Explorer method only lists files on disk, so none of this goes through it. Open Editors handles unsaved buffers, and a built-in command covers the clipboard. Selected blocks are the odd one out and need the Partial Diff extension.

Unsaved and untitled editors

  1. Open the Explorer view and expand the OPEN EDITORS section.
  2. Right-click the first editor and choose Select for Compare.
  3. Right-click the second editor and choose Compare with Selected.

Two scratch buffers work too. The File: Compare New Untitled Text Files command opens two empty editors, so you can paste text into each and compare them without creating a file.

Clipboard and last saved version

The shortcuts in the table are the ones the docs list for Windows and Linux.

CommandShortcut (Windows, Linux)Compares
File: Compare Active File with ClipboardCtrl+K CActive file vs. copied text
File: Compare Active File with SavedCtrl+K DActive file vs. last save
File: Compare New Untitled Text FilesNo default shortcut listedTwo pasted buffers

Those shortcuts come from the VS Code editing documentation. Compare with Saved is the quick check before you close a file you edited without a plan.

Selected text blocks

The documented VS Code comparison commands work on whole files, so a selection needs help. Partial Diff is an open-source extension that installs like any other VS Code extension.

Select Text for Compare marks the first block, and Compare Text with Previous Selection diffs the second block against it. Compare Text with Clipboard does the same against copied text, while Compare Text in Visible Editors diffs the text of editors shown side by side.

For a one-off comparison, skip the extension. Paste both blocks into untitled editors and use the command above.

How to compare a file with its Git history

YouTube player

Timeline is the quickest way to compare one file across commits. Open the file, expand Timeline in the Explorer view, and right-click a Git commit to choose Select for Compare. Right-click a second commit and choose Compare with Selected. The first revision lands on the left and the second on the right, and the diff covers that one file only.

Whole-commit and branch comparisons live somewhere else. And Git has to be tracking the file, or none of this applies.

Source Control view, Timeline and Graph

For working changes, open the Source Control view with Ctrl+Shift+G and select a file under Changes (unstaged edits) or under Staged Changes (what the next commit will contain). Timeline, as described above, lists Git commits and local saves for the active file.

For whole commits and branches, right-click a commit in the Source Control Graph, choose Compare with…, then pick a branch, remote branch or tag. The same menu offers Compare with Remote and Compare with Merge Base.

Since 1.89 (April 2024), Git: View Changes, Git: View Staged Changes and Git: View Untracked Changes open the multi-file diff editor. Comparing branches on the web is a separate job, covered in this guide to comparing branches in GitHub.

GitLens

GitLens adds revision commands the built-in views lack. Open Changes with Previous Revision is gitlens.diffWithPrevious, and Open Changes with Working File is gitlens.diffWithWorking.

Open Changes with Revision… (gitlens.diffWithRevision) compares the current file with any revision of the same file. There is also a Search & Compare view that lines up any two branches, tags or commits.

GitKraken’s documentation, updated November 2026, notes that features marked PRO require a trial or paid plan for use on privately hosted repositories. Check which commands you rely on before assuming they stay free.

For one file against one earlier commit, Timeline is enough. Add GitLens when branch comparison becomes routine.

git difftool

git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'

Guides on GitHub gists still tell you to add both lines by hand. The usual form is difftool.vscode.cmd set to code --wait --diff $LOCAL $REMOTE.

But Git itself ships a vscode tool definition, added in Git 2.47 (October 2024). Its diff command runs the editor with --wait --diff on $LOCAL and $REMOTE. On Git 2.47 or later, git difftool --tool=vscode should work without the second line, and git difftool --tool-help shows whether your build lists it.

The --wait flag keeps Git paused until the diff tab closes, so each changed file opens in turn. Reach for it when the plain git diff output in the terminal is too long to read.

Which extensions extend the built-in diff?

The built-in editor can’t compare folders, and it has no language-aware mode. Compare Folders and Diff Folders cover the first gap, SemanticDiff the second. For two small saved files, install nothing.

ExtensionAddsDocumented limit
Compare FoldersContent-based folder comparison with side-by-side diffsNo support for .gitignore files in subfolders
Diff FoldersFavorites, history, and end-of-line, whitespace and byte order mark optionsWhitespace and line-ending options cover ASCII and UTF-16 text only
SemanticDiffParser-based comparison of codeWorks only for supported languages and syntactically valid code

Compare Folders

The Marketplace listing from publisher MoshFeu shows 718,466 installs.

It launches from the Command Palette or the Compare Folders panel in the Activity Bar, and right-clicking two selected folders in the file explorer works as well. A terminal launch exists too, with COMPARE_FOLDERS=DIFF code path/to/folder1 path/to/folder2.

excludeFilter and includeFilter take glob strings.

Comparing local and remote folders over SSH has reported issues. The ignoreStrings option also reads every compared text file into memory, so it may be slow on large files.

Diff Folders

Run the New Diff Panel command or press Ctrl+L Ctrl+L (Cmd+L Cmd+L on macOS). Right-clicking folders in the Explorer and using Select for Compare and Compare with Selected works as well.

l13Diff.maxFileSize caps comparison size, and 0 means no limit. Files larger than the maximum buffer length are treated as binary.

SemanticDiff

According to SemanticDiff’s documentation, general-purpose diff viewers compare text line by line. The extension instead parses both versions of the code into syntax trees, which lets it hide irrelevant changes and detect moved code.

Install it from the Marketplace, then click the icon in the upper-right corner of any diff to switch to smart diff mode.

Check language support first. The extension handles only the languages it has rules for, and files in other formats fall back to a basic diff without most of these features.

Which comparison method fits which job?

Match the method to where the content lives right now. Saved files go through the Explorer, shell paths through code --diff, and everything else has its own route.

SourceFastest routeNeeds
Two saved files in the workspaceExplorer: Select for CompareBoth files in the open folder
Two paths already in a shellcode --diffcode on PATH
Unsaved or pasted textOpen Editors, or two untitled editorsText sitting in editor tabs
Active file vs. clipboard or last saveCtrl+K C or Ctrl+K DActive file only
File vs. earlier commitTimeline: Select for CompareGit repository
Two foldersCompare Folders or Diff FoldersExtension install

Decision rules

If both files are on disk, use the Explorer. Switch to the terminal only when the paths are already on your screen.

If one side is a selected block, paste both blocks into untitled editors first. Partial Diff pays off when you do this daily.

For history on a single file, Timeline beats GitLens.

Don’t install an extension to compare two saved files. Keep the shortcuts from this table in a VS Code workflow cheat sheet instead.

When does the built-in diff editor fall short?

It struggles with very large files and with line-ending-only changes. It was never meant for comparisons with more than two sides, or for non-text files. Some of these have a fix, and some just need a different tool.

Large files and timeouts

The diff computation is capped by diffEditor.maxComputationTime, which the default settings list at 5000 milliseconds, and by diffEditor.maxFileSize, listed at 50 MB. A value of 0 means no timeout or no limit.

When a diff times out, the result can mislead. The Monaco diff provider flags a timed-out computation as possibly inaccurate.

Both limits are ordinary VSCode settings. Raising them on a huge file buys accuracy and costs responsiveness, so the terminal command git diff --no-index file1 file2 is the better fallback.

Line endings

Sources disagree about what a line-ending-only change looks like. Review sites such as GitHub can show an entire file as changed when only the line endings differ.

VS Code may do the opposite. An issue opened in April 2020 on versions 1.44.2 and 1.45 Insiders reports that the diff UI does not show line-ending differences, even with Ignore Trim Whitespace set to false. The report predates current builds, so test your version with two copies of one file before trusting it.

Clicking the LF or CRLF label at the bottom right of the window shows or changes a file’s line ending. files.eol only sets the default for new files, so old files keep their endings.

Other wrong-fit cases

The diff editor has two sides, so three-way comparison is out. Binary and image files have no text diff to show.

And comparing is not merging. For conflicts, read how to resolve merge conflicts in Git instead.

VSCode Diff Editor FAQ

Does the VSCode diff editor need an extension?

No. Compare Active File With…, Compare Active File with Clipboard, Select for Compare and code --diff all ship with VS Code.

Extensions only fill gaps, mainly folder comparison and language-aware diffs, plus selected-text diffs.

Can I assign a keyboard shortcut to the compare command?

Yes. Open the Keyboard Shortcuts editor with Ctrl+K Ctrl+S (Cmd+K Cmd+S on macOS), search for Compare Active File With, and assign a key.

Avoid chords that collide with Ctrl+K C, which already compares the active file with the clipboard.

Does comparison work over Remote-SSH or WSL?

Yes, for files inside the connected workspace. The VS Code Server hosts extensions that interact directly with the remote workspace and file system.

Extensions are the weak point. Compare Folders lists reported issues when comparing local and remote folders over SSH, so keep both sides on the same host.

How do I close a diff without closing the files?

Press Ctrl+W (Cmd+W on macOS) on the diff tab. A diff is its own editor, so file tabs opened separately stay where they are.

For Git diffs, the Git: Close All Diff Editors command, added in 1.65 (February 2022), shuts every open diff at once.

Set Up the VSCode Diff Editor Once

Most of the setup is a one-time job. Bind the compare command first, because it runs on every file pair. The settings come second since they shape each diff, and the git difftool entry comes last because it only pays off inside Git repositories.

In practice that means a keybinding for File: Compare Active File With…, then diffEditor.ignoreTrimWhitespace set to false, hideUnchangedRegions.enabled set to true and maxComputationTime set to 0. Finally, diff.tool goes to vscode with code --wait --diff.

Each choice has a cost. Showing whitespace changes adds noise to reformatted files, and a maxComputationTime of 0 removes the time cap, so a very large file holds the editor until the comparison finishes.

These defaults and command names were verified in November 2026. A VS Code release that changes a default changes this advice, so check Preferences: Open Default Settings (JSON) after each major update.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.