• Qty: 14
  • Reply:11
  • Users:6

Compare two text files in VS Code


Here are the most common and reliable ways to **compare two text files** (or any files) side-by-side in **Visual Studio Code**

 (as of 2026 — the built-in diff tool hasn't changed significantly in recent versions).


### Method 1: Quickest way (using Explorer – recommended for most cases)


1. Open VS Code and make sure both files are visible in the **Explorer** sidebar (left panel):

   - Either open the containing folder via **File → Open Folder…**

   - Or just drag & drop the two files into VS Code (they appear under **Open Editors** if unsaved)


2. In the Explorer (or Open Editors list):

   - Right-click the **first file** → **Select for Compare**

   - Right-click the **second file** → **Compare with Selected**


3. VS Code instantly opens a beautiful side-by-side (or inline) diff view:

   - Added lines = green

   - Removed lines = red

   - Changed lines = highlighted

   - You can navigate changes with the arrows in the toolbar


This works for:

- Saved files in the same project/folder

- Unsaved/untitled files

- Files from different folders (as long as both are open in VS Code)


### Method 2: Using Command Palette (very flexible)


1. Press **Ctrl+Shift+P** (or **Cmd+Shift+P** on macOS) to open the Command Palette

2. Type **compare** and pick one of these:


   - **File: Compare Active File With…** → choose any other open file or browse to a file

   - **File: Compare New Untitled Text Files** → great when you want to paste/compare two pieces of text quickly without saving


### Method 3: From command line (outside VS Code)


If both files already exist on disk:


```bash

code diff path/to/file1.txt path/to/file2.txt

```


This opens VS Code directly in diff mode (very handy in scripts or terminals).


### Bonus tips


- **Switch to inline view** → click the little "parallel/inline" toggle button in the diff toolbar (useful on narrow screens)

- **Ignore whitespace** → click the gear icon in the diff toolbar → toggle "Ignore Trim Whitespace"

- **Word-level diff** → same gear menu → "Word Diff"

- **Compare with clipboard** → select text → right-click → **Compare Active File with Clipboard** (or use command palette)

- If the diff feels slow on very large files → go to **Settings** (Ctrl+,) → search for "diff" → try changing **Diff Algorithm** to "legacy"


The Explorer right-click method ("Select for Compare" → "Compare with Selected") is what most people use daily — it's fast and intuitive.


Let me know if you're comparing git versions, very large files, or folders instead — there are slightly different flows for those!


Like to reply
Tomlist

Tomlist#1

Visual Studio Code does **not** have a built-in feature to compare two entire folders (directories) 

side-by-side for differences in files, additions, deletions, etc. — unlike file comparison, which is native.


The most popular and reliable way is to use a free extension from the VS Code Marketplace. As of 2026, 

two strong, actively maintained options stand out:


1. **Compare Folders** by MoshFeu (most popular — over 620k installs, last major update in 2025)

   - Link: https://marketplace.visualstudio.com/items?itemName=moshfeu.compare-folders


2. **Diff Folders** by L13RARY (good alternative with multi-panel support)

   - Link: https://marketplace.visualstudio.com/items?itemName=L13RARY.l13-diff


### Recommended: Install "Compare Folders" (easiest & feature-rich)


1. Open VS Code

2. Go to the **Extensions** view (Ctrl+Shift+X or Cmd+Shift+X on macOS)

3. Search for **Compare Folders** (publisher: MoshFeu)

4. Click **Install**


### How to use it (several convenient ways)


**Option A – From Explorer (fastest once set up)**  

- In the Explorer sidebar, select **two folders** (hold Ctrl/Cmd to multi-select if needed, or just right-click 

one then the other)  

- Right-click → **Compare selected folders**  

  → It opens the comparison view immediately.


**Option B – Command Palette**  

- Press **Ctrl+Shift+P** (Cmd+Shift+P on macOS)  

- Type and select:  

  - **Compare Folders: Choose 2 folders and compare** → pick any two folders from your file system  

  - or **Compare Folders: Compare a folder against workspace** → if one folder is already your open

 workspace/project


**Option C – Dedicated panel**  

- After installing, a new **Compare Folders** icon appears in the Activity Bar (left sidebar — looks like 

two folders/arrows)  

- Click it → then click to select Left folder and Right folder  

- It shows:  

  - Tree or list view of differences  

  - Categories: Added, Modified, Deleted, Identical (toggleable)  

  - Click any file → opens side-by-side diff (same as native file compare)  

  - Actions: Copy left→right, right→left, delete, etc. (with confirmation prompts)


### Useful settings (after install, go to Settings → search "compareFolders")


- **excludeFilter** — ignore folders like node_modules, .git, etc. (add `["**/node_modules", "**/.git"]`)

- **ignoreWhiteSpaces** / **ignoreLineEnding** / **ignoreEmptyLines** — very helpful for cleaner diffs

- **respectGitIgnore** — honors .gitignore files

- **showIdentical** — hide/show unchanged files

- CLI shortcut: From terminal run  

  ```bash

  COMPARE_FOLDERS=DIFF code /path/to/folderA /path/to/folderB

  ```


### Quick alternatives if you don't want an extension


- Use **Git** (if the folders are git repos or you can init them temporarily):  

  1. Put one folder inside the other or use separate clones  

  2. Run `git diff no-index folderA folderB` in terminal → VS Code can open that output nicely with `code -`


- External free tools (outside VS Code): WinMerge (Windows), Meld (cross-platform), Beyond Compare

 (paid but excellent), or command-line `diff -r folder1 folder2`


The "Compare Folders" extension gives you the closest experience to a native folder diff inside 

VS Code — tree view + file diffs + copy actions. Install it and you'll use it constantly once you need folder 

comparisons.


Let me know if you're on Windows/macOS/Linux or comparing very large folders (some settings help

 performance)!


2 M 11 D 15:03
Tomlist

Tomlist

Digital Signature matters, Next-Generation Digital Identity & Customer Identity Management.