Visual Studio Code - is there a Compare feature like that plugin for Notepad ++?

Visual Studio-Code

Visual Studio-Code Problem Overview


Is there a Compare feature like the Plugin for Notepad++?

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

right click on first file and select

enter image description here

then right click on second file and select

enter image description here

Screencast:

how to compare files in vscode

Solution 2 - Visual Studio-Code

You can compare files from the explorer either from the working files section or the folder section. You can also trigger the global compare action from the command palette.

  1. Open a folder with the files you need to compare,
  2. Select two using SHIFT
  3. Right click "Compare Selected" enter image description here

Solution 3 - Visual Studio-Code

I have Visual Studio Code version 1.27.2 and can do this:

Compare two files
  1. Drag and drop the two files into Visual Studio Code enter image description here
  2. Select both files and select Select for Compare from the context menu enter image description here
  3. Then you see the diff enter image description here
  4. With Alt+F5 you can jump to the next diff enter image description here
Compare two in-memory documents or tabs

Sometimes, you don't have two files but want to copy text from somewhere and do a quick diff without having to save the contents to files first. Then you can do this:

  1. Open two tabs by hitting Ctrl+N twice: enter image description here
  2. Paste your first text sample from the clipboard to the first tab and the second text sample from the clipboard to the second tab
  3. Select the first document Untitled-1 with Select for Compare: enter image description here
  4. Select the second document Untitled-2 with Compare with Selected: enter image description here
  5. Then you see the diff: enter image description here

Solution 4 - Visual Studio-Code

Here is my favorite way, which I think is a little less tedious than the "Select for Compare, then Compare With..." steps.

  • Open the left side file (not editable)
  • F1 Compare Active File With...
  • Select the right side file (editable) - You can either select a recent file from the dropdown list, or click any file in the Explorer panel.

This works with any arbitrary files, even ones that are not in the project dir. You can even just create 2 new Untitled files and copy/paste text in there too.

Solution 5 - Visual Studio-Code

Another option is using command line:

code -d left.txt right.txt

Note: You may need to add code to your path first. See: https://stackoverflow.com/questions/29963617/how-to-call-vs-code-editor-from-command-line

Solution 6 - Visual Studio-Code

In your terminal type:

code --diff file1.txt file2.txt

A tab will open up in VS Code showing the differences in the two files.

Solution 7 - Visual Studio-Code

There is plugin called Partial Diff which helps to compare text selections within a file, across different files, or to the clipboard.

Solution 8 - Visual Studio-Code

If you want to compare file in your project/directory with an external file (which is by the way the most common way I used to compare files) you can easily drag and drop the external file into the editor's tab and just use the command: "Compare Active File With..." on one of them selecting the other one in the newly popped up choice window. That seems to be the fastest way.

Solution 9 - Visual Studio-Code

I found a flow which is fastest for me, by first associating a keyboard shortcut Alt+k to "Compare Active File With..." (#a). (Similar to wisbucky's answer but further improved and more step-wise.)

Then, to compare two files:

  1. Open or focus file B (will be editable in compare view by default). E.g. by drag-drop from File Explorer to VS Code's center.
  2. Open or focus file A.
  3. Press Alt+k, a quick open menu will be shown with file B focused.
  4. Press Enter.

Result: file A on left and file B on right. (Tested on VS Code 1.27.1)

Remarks

#a - to do so, press Ctrl-k Ctrl-s to show Keyboard Shortcuts, type compare on the top search box, and double click the "Keybinding" column for "Compare Active File With...", press Alt+k then Enter to assign it.

Solution 10 - Visual Studio-Code

Here's a link to marketplace for extension. Extension "compareit" helps to compare two files wich you can choose from your current project and other directory on your computer or clipboard.

Solution 11 - Visual Studio-Code

Right click on 1st file click "Select for compare".

Click 2nd file click "Compare with selected"

Solution 12 - Visual Studio-Code

In my case, I was trying to use compare option for files in open editor of VS code, however open editor wasn't visible. In such a case, to access open editor, click on 3 dots next to explorer and check the open editors option.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser4863890View Question on Stackoverflow
Solution 1 - Visual Studio-CodeRakka RageView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeBenjamin PaseroView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeLernkurveView Answer on Stackoverflow
Solution 4 - Visual Studio-CodewisbuckyView Answer on Stackoverflow
Solution 5 - Visual Studio-CodewisbuckyView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeErika DsouzaView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeSANN3View Answer on Stackoverflow
Solution 8 - Visual Studio-CodeJacek DziurdzikowskiView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeJohnny WongView Answer on Stackoverflow
Solution 10 - Visual Studio-CodeMargaretView Answer on Stackoverflow
Solution 11 - Visual Studio-CodeAli KaracaView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeShaggyView Answer on Stackoverflow