Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do you code compare in Visual Studio Code?

Open VS Code with the files you are going to compare. Right-Click one file you want to compare => Select for Compare.

Which is better Notepad or Visual Studio Code?

When comparing Notepad++ vs Visual Studio Code, the Slant community recommends Visual Studio Code for most people. In the question“What are the best programming text editors?” Visual Studio Code is ranked 3rd while Notepad++ is ranked 12th.

Can I compare 2 files in Visual Studio?

locate the required file in the Solution Explorer window, right-click it and choose Compare Selected File in the context menu; open the required file in Visual Studio, right-click the required document name in the document tab well and in the document's context menu select Compare Current File.


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


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

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

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.


Another option is using command line:

code -d left.txt right.txt

Note: You may need to add code to your path first. See: How to call VS Code Editor from command line


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.