Lately I got questions asking for a quick lightweight tool to compare code files. Even though there are several tools like Beyond Compare, Araxis Merge, etc… which have lot of comparison and merging features, I use Visual Studio Code for quick file comparison during development or otherwise. For me, VS Code comes in handy as it is cross platform and I am using it on both macOS and Windows. I am using it for minor project development and even as a simple text editor. So naturally VS code is my go-to tool for file comparison. Here are the simple steps to compare the contents of two code files in VS Code.
Steps to compare contents of two files
- Open both the files in VS Code.
- From the left Explorer panel, right-click the first file and choose Select for Compare from the right-click menu.
- Then right-click the second file and choose Compare with Selected.
- Both the files will be opened in the main panel, side by side in inline view mode which is comfortable for comparing the differences.
- More about Visual Studio Code here.
6 thoughts on “How to compare contents of two files in Visual Studio Code?”
good information thanks for shared .. !!!
Helped me a lot. Thanks
Is there an easy way to move or copy code from one of the files being compared to the other? I ask, because VSCode’s comparison algorithm works better the Beyond Compare’s for many XML files, but Beyond Compare’s ability to move code between the two files is very good.
As of now, VS Code do not have merging or copying features in the compare view. Looks like a feature request (https://github.com/microsoft/vscode/issues/25887) is in the development backlog. Not sure when it will be taken up for development. So, for now we have to manage with one of the extensions from VS Code Marketplace.
Can this also be done with files in two different projects / windows?
We can’t compare files between different windows. However, If you open the specific file alone from project-A from within project-B window, then you can compare it.