You have two versions of a config file, a JavaScript module, or a Python script and you need to know exactly what changed. Knowing how to compare two files in VS Code is one of the most essential developer skills — yet most teams only know one or two of the available methods. This guide covers every way to run a file diff inside VS Code: the Explorer right-click method, the vscode diff two files CLI flag, the Command Palette, keyboard shortcuts, and relevant settings. It also explains where vs code compare two files hits its limits and when a dedicated visual diff tool fills the gaps.

Why File Diffing Matters for Developers

original.js 1 const port = 3000; 2 const host = 'localhost'; 3 const timeout = 5000; 4 app.listen(port, host); 5 ~ console.log('Server up'); 6 module.exports = app; modified.js 1 const port = 3000; 2 const host = 'localhost'; 3 + const timeout = 10000; 4 app.listen(port, host); 5 ~ console.log('ready on :3000'); 6 module.exports = app; Removed line Added line Changed line Character-level highlights show exact characters that changed — not just the whole line.
A file diff compares two versions side-by-side: red lines were removed, green lines were added, yellow lines were modified. Character-level highlights pinpoint the exact characters that changed.

A file diff — short for "difference" — is a structured comparison of two text files that identifies every line that was added, removed, or changed between them. The concept dates to 1974 when the Unix diff utility was released. Fifty years later, code diffing remains one of the most fundamental operations in software development.

Developers rely on file diffs for several critical workflows:

  • Code review: Pull request diffs let reviewers see precisely what a contributor changed without reading the entire file. Industry research suggests developers spend a significant share of their working time in code review — the quality of the diff compare view directly affects that time.
  • Debugging regressions: When a deployment breaks something, diffing the deployed file against the previous version immediately surfaces the culprit line.
  • Configuration management: Comparing production.yaml against staging.yaml or a new dependency's lockfile against the previous one is a daily sysadmin and DevOps task.
  • Merging conflicts: Three-way merge tools use a base file plus two branches — the underlying operation is two separate diffs combined.
  • Documentation changes: Tech writers and DevRel engineers diff Markdown or reStructuredText files to track what changed between doc versions.

Visual Studio Code is the most popular code editor in the world — as of the 2024 Stack Overflow Developer Survey, 73.6% of professional developers use it as their primary editor. Its built-in visual studio code compare files capabilities are therefore the most widely accessible diff tool in existence. Here is how to use every one of them.

Method 1: Compare Two Files in VS Code Using the Explorer

Visual Studio Code — my-project EXPLORER ▾ my-project ▾ src 📄 config.v1.js 📄 config.v2.js 📄 app.js 📄 package.json Open Open to the Side Cut Copy Compare with Selected Select for Compare Reveal in File Explorer Delete 1 Select for Cmp 2 Compare with Sel.
Step 1: right-click the base file and choose "Select for Compare". Step 2: right-click the second file and choose "Compare with Selected". VS Code opens the diff editor instantly.

The Explorer context menu method is the most discoverable way to run a vscode diff two files comparison — no command memorization required.

Step-by-step

  1. Open the Explorer panel (Ctrl+Shift+E on Windows/Linux, Cmd+Shift+E on macOS).
  2. Right-click the first file (the "old" or "base" version) and select Select for Compare. VS Code stores this selection silently — there is no visual confirmation, which trips up first-time users.
  3. Right-click the second file (the "new" or "changed" version) and select Compare with Selected. VS Code opens the diff editor immediately.
Tip: You can compare files across different folders in the same workspace, or even across roots in a multi-root workspace. The Explorer-based compare approach works as long as both files are visible in the Explorer tree.

The diff editor opens in split view by default: the base file on the left, the changed file on the right. Red gutters mark removed lines; green gutters mark added lines. Within a changed line, character-level highlights show the exact characters that differ — which is what makes the VS Code visual diff workflow so much faster than reading a raw git diff in the terminal. This is the most popular way to compare two files vscode provides out of the box.

Method 2: VS Code Diff from the Command Line

If you are already in a terminal, the fastest way to open a vs code diff two files session is the --diff flag:

code --diff file1.txt file2.txt

VS Code launches (or focuses an existing window) and immediately opens the two files in the diff editor. This vs code diff two files approach works with relative or absolute paths, and with any file type VS Code can open — making it the fastest way to vscode diff two files from outside the GUI.

Practical examples

# Compare two config files
code --diff nginx.conf.bak nginx.conf

# Compare files in different directories
code --diff src/v1/app.js src/v2/app.js

# Diff a file against a temporary edit
code --diff original.py /tmp/patched.py

The --diff flag also accepts a --wait flag (code --diff --wait file1 file2), which blocks the terminal until the diff editor tab is closed. This is useful when scripting: you can open a diff, wait for confirmation, then continue with the next step.

Git integration: Configure VS Code as your Git difftool by running git config --global diff.tool vscode and git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'. After that, git difftool filename opens the vscode compare diff editor for any file in your Git history.

Method 3: VS Code Diff via the Command Palette

The Command Palette exposes every VS Code command by name — including the compare files vscode commands — making it the best keyboard-driven approach to vscode compare workflows. If you prefer to compare files in visual studio Code without touching the mouse, this is your go-to method.

Compare active file with another file

  1. Open the file you want to use as the base in the editor.
  2. Open the Command Palette: Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
  3. Type File: Compare Active File With... and press Enter.
  4. A file picker appears. Type a partial filename or navigate to the target file, then press Enter.

Compare active file with clipboard

  1. Copy any text to your clipboard.
  2. Open the Command Palette and type File: Compare Active File with Clipboard.
  3. VS Code creates a temporary diff against the clipboard contents — useful for comparing a snippet you just copied from a Stack Overflow answer or documentation against your existing implementation.

Compare two open editor tabs

  1. Right-click any open editor tab (not the Explorer file) and select Compare Opened Editors if both files are already open. Alternatively, use the Command Palette: File: Compare Open Editors.
Searching commands: You do not need to type the full command name. "compare" or "diff" in the Command Palette is enough to surface the relevant commands. Anyone who wants to compare files in visual studio Code can rely on the fuzzy matcher — partial words and typos still find the right command.

Understanding VS Code's Diff Viewer

config.v1.js ↔ config.v2.js ⇔ Toggle Inline View config.v1.js 2 changes config.v2.js 1 const port = 3000; 2 const timeout = 5000 ; 3 app.listen(port); 4 console.log('Server up'); ⋯ 3 unchanged lines ⋯ 1 const port = 3000; 2 const timeout = 10000 ; 3 app.listen(port); 4 console.log('ready on :3000'); ⋯ 3 unchanged lines ⋯ ▲ Prev Alt+Shift+F5 ▼ Next Alt+F5 Red gutter = removed Green gutter = added Char-level highlight = exact diff within line
The VS Code diff viewer: red gutter markers highlight removed lines, green markers highlight added lines, and character-level highlights pinpoint the exact characters that changed within a modified line. The overview ruler (far right strip) maps all changes across the entire file.

Once the diff editor is open, VS Code gives you a rich interface for navigating and understanding changes. Whether you triggered the comparison from the Explorer or the CLI, the diff viewer looks and behaves the same. Here is what each element means.

Split view vs. inline view

By default the vs code compare two files view opens in split mode: the original file on the left, the modified file on the right, with coloured gutter markers indicating changed regions. Click the Toggle Inline View button (or run View: Toggle Diff Inline View from the Command Palette) to switch to unified view, which interleaves additions and deletions in a single column. Unified view is often easier to read for small, scattered changes; split view works better for large sections that were rewritten.

Colour coding

  • Green (full line): A line that exists in the right-hand (modified) file but not the left-hand (original) file — an addition.
  • Red (full line): A line that exists only in the original file — a deletion.
  • Darker highlight within a line: Character-level differences inside a line that changed. For example, if only a port number changed from 3000 to 8080, only those characters are highlighted, not the whole line.

Gutter decorations and fold/expand

Unchanged sections between diff blocks are collapsed by default into "N unchanged lines" fold regions. Click the expand arrow to reveal the context lines. You can control how many unchanged lines to show as context via the diffEditor.contextLines setting (default: 3).

The diff overview ruler

The minimap-style ruler on the far right of the diff editor shows the entire file at a glance, with coloured markers for every changed region. This is especially helpful when comparing large files — you can click anywhere on the ruler to jump to that region without scrolling.

The vscode diff viewer also shows a change summary in the editor tab title — for example, modified.js (2 changed regions) — so you know the scale of the diff before you start navigating.

Essential VS Code Diff Shortcuts and Settings

VS Code Diff — Keyboard Shortcuts ACTION WINDOWS / LINUX macOS Next change Alt + F5 Opt + F5 Previous change Shift + Alt + F5 ⇧ Opt + F5 Open Command Palette Ctrl + Shift + P Cmd + Shift + P Open Explorer Ctrl + Shift + E Cmd + Shift + E Open Integrated Terminal Ctrl + ` Cmd + `
Essential VS Code diff keyboard shortcuts. Use Alt+F5 to jump to the next change and Shift+Alt+F5 for the previous — no mouse required. Ctrl+Shift+P opens the Command Palette where you can type "Toggle Inline View" to switch diff modes.

Navigation shortcuts

Action Windows / Linux macOS
Next change Alt+F5 Option+F5
Previous change Shift+Alt+F5 Shift+Option+F5
Toggle inline view Command Palette → "Toggle Inline View" Command Palette → "Toggle Inline View"
Open Command Palette Ctrl+Shift+P Cmd+Shift+P
Open Explorer Ctrl+Shift+E Cmd+Shift+E
Open integrated terminal Ctrl+` Cmd+`

Key settings to configure

Open VS Code settings (Ctrl+,) and search for "diff" to find these options:

  • diffEditor.renderSideBySide (default: true) — Set to false to default to inline/unified view instead of split view.
  • diffEditor.ignoreTrimWhitespace (default: true) — When enabled, trailing whitespace changes are not highlighted. Disable this if you need to audit whitespace changes in Python or YAML, where indentation is semantic.
  • diffEditor.contextLines (default: 3) — Number of unchanged lines shown around each diff block. Increase for more context, decrease to focus only on changes.
  • diffEditor.wordWrap (default: off) — Enable to wrap long lines in the diff editor, useful for comparing Markdown or minified JSON.
  • diffEditor.experimental.showMoves (default: false) — Experimental feature that detects when code blocks were moved rather than deleted and re-added, drawing connecting lines between the old and new positions.

Configuring VS Code as your Git difftool

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

After this one-time setup, running git difftool HEAD~1 -- src/app.ts will open the VS Code diff editor directly — a handy vs code compare shortcut for Git users. The --wait flag ensures Git waits for you to close the diff tab before moving on.

When VS Code Diff Falls Short

VS Code's built-in vs code diff viewer is excellent for developers who are already working inside the IDE. But there are common situations where it is not the right tool:

  • You are not in VS Code. Launching the entire IDE just to compare a configuration file or a copied snippet adds 5–15 seconds of startup time and context switching overhead. If you are in a browser, a dedicated browser-based diff tool is faster.
  • You need to compare Office documents or PDFs. VS Code's diff editor only works with text files it can parse. It cannot open .docx, .xlsx, .pptx, or .pdf files as diffable content. If a colleague emails you two versions of a Word document, VS Code is not the right tool — see our guide on how to compare two Word documents for document-specific methods.
  • You want diff statistics. VS Code does not show an "added X lines, removed Y lines, N% similarity" summary. For quick sanity checks — "how different are these really?" — a stats bar is useful.
  • You need JSON key-order normalization. If two JSON config files have identical values but different key orderings, VS Code will show every line as changed. A tool that sorts keys before diffing eliminates this noise entirely.
  • You want an AI summary of the diff. VS Code's diff view is purely visual — it does not explain why something changed or summarize the semantic intent of a large diff in plain English.
  • You are comparing lists or structured data. For comparing CSV rows, SQL query outputs, or plain text lists, see our guide on how to compare two lists.
  • Privacy and context. If you are comparing sensitive code outside of your local machine — on a shared terminal, a cloud IDE, or a colleague's machine — launching VS Code with your full workspace profile may expose unrelated files and settings. For a broader look at how to spot the difference between any two texts, our companion guide covers additional approaches.

These gaps are exactly where the Diff Checker Chrome extension picks up. It is a browser-based diff compare tool that requires no IDE, no installation beyond a Chrome extension, and runs entirely client-side so your code never leaves your machine.

Tool Comparison: VS Code Diff vs. Diff Checker Extension

VS Code Diff vs Diff Checker Extension VS Code Built-in Diff Checker Ext. Requires IDE open Split & unified view Office docs (DOCX, XLSX, PPTX) PDF comparison JSON key-sort normalization Diff stats bar (added / removed / %) AI diff summary Copilot only Multiple diff algorithms 1 (Myers) 3 algorithms Cost Free Free
Feature-by-feature comparison. Both tools share the same Monaco Editor rendering engine. VS Code wins for deep IDE integration; Diff Checker wins for format flexibility, stats, and browser-based workflows.

Both tools use Monaco Editor under the hood — the same rendering engine — so the visual diff experience looks familiar. The differences are in scope, context, and workflow:

Feature VS Code Built-in Diff Diff Checker Extension (v1.1.7)
Requires IDE to be open Yes No — runs in any Chrome tab
Rendering engine Monaco Editor Monaco Editor (same engine)
Split view Yes Yes
Unified (inline) view Yes Yes
Syntax highlighting All VS Code languages (100+) 15+ languages (JS, TS, Python, Java, Go, Rust, SQL, etc.)
Office docs (DOCX, XLSX, PPTX) No Yes — text extracted automatically
PDF comparison No Yes
JSON normalization (key sort) No Yes
Diff algorithms Myers / LCS (one algorithm) Smart Diff, Ignore Whitespace, Classic LCS (three algorithms)
Code formatting (Prettier) Via separate Prettier extension Built-in for 8+ languages
AI diff summary No (Copilot can help separately) Yes — optional, OpenAI-powered (GPT models)
Diff stats bar (added/removed/% similarity) No Yes
Data privacy Fully local (files stay on disk) Fully client-side (data stays in browser)
Cost Free (bundled with VS Code) Free Chrome extension
Compare without saving files Partial (clipboard diff via Command Palette) Yes — paste any text directly

The two tools are complementary, not competing. Use the visual studio code compare workflow when you are already in the IDE doing a code review or debugging a regression. Use Diff Checker when you need a quick diff compare without opening VS Code, when your files are Office documents or PDFs, or when you want normalized JSON comparison or an AI-generated summary to share with a non-technical colleague.

If you work with Excel spreadsheets, the same logic applies — see our guide on how to compare 2 Excel files for differences for file-format-specific advice. And if you are looking for diff tools that work at the static analysis level — catching bugs rather than content differences — see our roundup of static code analysis tools.

Frequently Asked Questions

How do I compare two files in VS Code?

Right-click the first file in the VS Code Explorer, choose Select for Compare, then right-click the second file and choose Compare with Selected. VS Code opens a side-by-side visual diff viewer immediately. Alternatively, use the command line: code --diff file1.txt file2.txt.

What is the keyboard shortcut to diff two files in VS Code?

Inside the diff editor, press Alt+F5 to jump to the next change and Shift+Alt+F5 to jump to the previous change. To toggle between split and unified view, open the Command Palette and search for Toggle Inline View.

Can VS Code compare binary files?

No. VS Code's built-in diff viewer only handles text-based files. If you open two binary files it will display a "binary files differ" message without a visual compare. For binary-adjacent formats like DOCX, XLSX, or PDF, use a tool like the Diff Checker browser extension that extracts text before running the diff compare.

Is there a VS Code extension for comparing files?

VS Code ships with a built-in file diff feature, so no extension is strictly required. However, marketplace extensions like Partial Diff add the ability to diff selected text ranges. For a browser-based alternative, the Diff Checker Chrome extension lets you compare the same file types VS Code handles — code, JSON, Office docs — without opening the IDE at all.

How do I compare two files side by side in VS Code?

Right-click the base file in the Explorer, choose Select for Compare, then right-click the second file and pick Compare with Selected. VS Code opens a side-by-side visual diff with the original on the left and the modified file on the right. You can also run code --diff file1 file2 from the terminal — VS Code opens the diff in split view by default.

What is the difference between VS Code diff and a dedicated visual diff tool?

The vs code diff feature is tightly integrated into the IDE and ideal for in-editor code diffing workflows. A dedicated tool like Diff Checker is browser-based, requires no IDE, supports non-text formats (DOCX, XLSX, PDF), and adds capabilities VS Code lacks — JSON normalization, multiple diff algorithms, a stats bar, and optional AI summaries.

Compare Files in Seconds — No IDE Needed

Diff Checker is a free Chrome extension powered by the same Monaco Editor as VS Code. Compare code, config files, Office documents, and PDFs directly in your browser — no VS Code window required. All processing is client-side: your code never leaves your machine.

  • Free, no account required
  • Monaco Editor — same engine as VS Code
  • Split view and unified view
  • Upload DOCX, XLSX, PPTX, PDF — text extracted automatically
  • Smart Diff, Ignore Whitespace, and Classic LCS algorithms
  • JSON key-sort and CSS property normalization
  • Diff stats bar: added / removed / % similarity
  • Optional AI summary (OpenAI-powered, your API key)
Add to Chrome — It's Free

Rated 5.0 stars · Used by 1,000+ users