How to get an external "diff" viewer, with N++ and the last "Compare" plugin, "v188.8.131.52"...
guy038 last edited by guy038
I was comparing two files, with the last
v184.108.40.206version of the excellent
Compareplugin of Pavel Nedev, ( alias @pnedev ), when I, suddenly, remembered that, in a prior version, it was possible to emulate a
diffviewer ! After investigation, looking in my plugins backups, this tool is, indeed, available from the
ComparePlugin.v220.127.116.11.bin.ziparchive ( and, probably, from version
v18.104.22.168, too ! )
And, in the change.log file, it is said :
v22.214.171.124 : 1. NEW: Loader for using N++ as an external diff viewer (e.g. in TortoiseSVN, TortoiseGit, ..) Syntax: .../Notepad++/plugins/ComparePlugin/compare.exe <file_path_1> <file_path_2> 2. ...
Unfortunately, this program is absent from the last archive
ComparePlugin_v2.0.0_x86.zip( and, probably, in the
ComparePlugin_v2.0.0_X64.zip, archive, too ), which can, both, be downloaded from :
So, I did a test to verify if that tool could be associated with the Compare plugin, version
126.96.36.199and I’m pleased to tell you that it works nice with the latest version, without any trouble ;-)) Here are, below, the different steps to use it properly :-))
Of course, I assume that the Compare plugin
v188.8.131.52is already installed, on your current N+++ configuration. So :
- 1) Download the
184.108.40.206.version of the Compare plugin, from that link :
2) From the ComparePlugin folder of that archive, extract the two files,
compare.ini, only :
In the folder
%AppData%\Notepad++\plugins\ComparePlugin\ComparePlugin, along with the two libraries
sqlite3.dll, if you previously installed Notepad++, with the Installer
<N++ installation> folder\plugins\ComparePlugin\ComparePlugin, along with the two libraries
sqlite3.dll, if your installation of N++ was a local installation, from a
ziparchive, in any folder
This post has been updated in order to mention the new architecture of plugins, since Notepad++ version
In case of a local N++ installation, these two files
compare.inimay, also, be placed anywhere, as soon as they are, both, in the same folder ! ( Just remember the absolute path, for further use ! )
- 3) Only in case of a local installation of Notepad++, as N++ is not locatable via registry, you must configure the
compare.inifile, by adding, in the
[Notepad]section, the line :
path=<ABSOLUTE path of Notepad++>\notepad++.exe
The environment variables, as, for instance,
%USERPROFILE%and/or the special directories
..can be used to constitute the absolute path
NO need to surround all the path, with single or double quotes, if your path contains spaces !
4) Now, close any running instance of Notepad++
5) Then, from the “Run” menu, start a
6) Inside the DOS console window, whatever the current directory is, type the command :
<ABSOLUTE path of compare.exe\compare.exe ABSOLUTE or RELATIVE path\File_A ABSOLUTE or RELATIVE path\File_B
with a usual space after the expressions compare.exe and File_A
=> Your current Notepad++ should start, soon, with, only, the two
File_Bfiles, already compared ;-))
Of course, the location of two compared files are completely independent !
If a path, absolute or relative, contains spaces, just surround it with double quotes
- 1) Download the
dinkumoil last edited by dinkumoil
For some unknown reason the solution @guy038 posted above doesn’t work anymore or at least not always. Thus I want to share an alternative solution. The basics for it have been found by @Ekopalypse in this thread.
To accomplish the comparison task in a user-friendly way we need the following:
- The Compare plugin (obviously).
- The NppExec plugin.
- An NppExec script to start comparison.
- A Batch script as the controller.
- A VBScript as launcher for the Batch script to avoid flickering console windows.
- An Explorer context menu entry.
The Compare Plugin
The Compare plugin can be installed using PluginManager (when using Notepad++ v7.5.9 or below) or PluginsAdmin (when using Notepad++ v7.6 or above). It is also possible to download it from this site (click on releases in the menu bar) and install it manually.
The NppExec Plugin
The NppExec plugin can be installed using PluginManager (when using Notepad++ v7.5.9 or below) or PluginsAdmin (when using Notepad++ v7.6 or above). It is also possible to donwload it from this site (click on releases in the menu bar) and install it manually.
The NppExec Script
After installing the NppExec plugin navigate in Notepad++ to
(menu) Plugins -> NppExec -> Execute.... Copy the following code and paste it into the edit area of the popped up window.
if $(SYS.NppCommand) == CompareFiles then npp_menucommand Plugins/Compare/Compare endif
Please note: The npp_menucommand command requieres the path to the menu item it should simulate a click on to be localized. That means you have to provide the name of the
Pluginsmenu in the locale your Notepad++ UI is set to.
The code checks if there is an environment variable
NppCommandwith the value
CompareFiles. If this is the case it triggers the Compare plugin to start file comparison by simulating a mouse click on the according menu entry.
Now click on button
CompareFilesOnStartupinto the combo box. This is the name the script can be called with. Then click the
Savebutton and close the dialog by clicking the
Now navigate to
(menu) Plugins -> NppExec -> Advanced Options...and select in the combo box under
Execute this script when Notepad++ startsthe
CompareFilesOnStartupscript you created above. Close the dialog by clicking the
The Controlling Batch Script
Open a new file in Notepad++ and paste the code below into it. Store it as
@echo off & setlocal set "File1Buffer=%TEMP%\NppCompare_File1.txt" if "%~2" neq "" ( set "File1=%~1" set "File2=%~2" ) else if not exist "%File1Buffer%" ( (set /p "=%~1" < NUL & echo.) > "%File1Buffer%" exit /b 0 ) else ( set /p "File1=" < "%File1Buffer%" set "File2=%~1" ) set "NppCommand=CompareFiles" start "" "%ProgramFiles(x86)%\Notepad++\notepad++.exe" "%File1%" "%File2%" del "%File1Buffer%" 1>NUL 2>NUL
The script can be called once, providing two file paths as parameters. In lines 6 and 7 they are copied to two internal variables.
The script can also be called twice, providing only one file path each. In this case it checks if a buffer file for storing the first file’s path already exists. If not it copies the provided file path to that buffer file and exits (lines 9 to 11).
To avoid problems with file paths containing special characters which would be interpreted as control characters by the Batch script interpreter, I use the
set /pcommand to write the file path to the buffer file. This way I can use double quotes, which prevent the evaluation of control characters by the Batch script interpreter, without writing these quotes to the buffer file.
If the buffer file already exists, the contained file path is read from it and stored into an internal variable to be used as the first file for comparison. The file path of the second file is taken from the provided parameter (lines 13 to 15).
As a last step an environment variable named
NppCommandis created and set to the value
CompareFiles(this variable is queried in the NppExec script above). After that Notepad++ is executed with the two file paths retrieved before as arguments (lines 18 to 19). By using the
startcommand it is possible to avoid the script getting paused until Notepad++ is closed. Instead execution continues immediatly.
Finally the buffer file for the first file’s path is deleted (line 21).
The VBScript Launcher Script
It would be possible to use the Batch script created above directly. But that would cause console windows popping up and disappearing immediatly, an ugly flickering effect.
For that reason we need the following launcher script. Open a new file in Notepad++, paste the code below into it and save it as
If WScript.Arguments.Count = 0 Then WScript.Quit Set objFSO = CreateObject("Scripting.FileSystemObject") Set objWshShell = CreateObject("WScript.Shell") strScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName) strScriptFullPath = objFSO.BuildPath(strScriptPath, "NppCompareFiles.cmd") strArgs = "" For intIdx = 0 To WScript.Arguments.Count - 1 strArgs = strArgs & """" & WScript.Arguments(intIdx) & """ " Next objWshShell.Run """" & strScriptFullPath & """ " & strArgs, 0, False
The script collects all the provided command line arguments one by one and generates a new command line consisting of the full path to the
NppCompareFiles.cmdscript and all the original command line arguments. Then it executes the Batch script in a hidden window, which avoids flickering console windows.
The Explorer Context Menu Entry
At first move both the two files
NppCompareFilesLauncher.vbsto a folder of your choice. For this How-To I will use
C:\Program Files (x86)\Notepad++\plugins\ComparePlugin\ComparePlugin.
Open a new file in Notepad++, paste the code below into it and save it as
NppCompareFiles.reg. In line 7 you have to provide the folder where you stored the two script files in the last step.
Please note: Strings in *.reg files have to follow the escaping rules of strings in the C programming language. That means that e.g.
\have to be escaped with the
\character, which causes the double-backslashes in the file’s content below.
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\CompareWithNpp] @="Compare with Notepad++" [HKEY_CLASSES_ROOT\*\shell\CompareWithNpp\command] @="wscript.exe /nologo \"C:\\Program Files (x86)\\Notepad++\\plugins\\ComparePlugin\\ComparePlugin\\NppCompareFilesLauncher.vbs\" \"%1\""
Now double-click the resulting *.reg file and confirm the UAC dialog and all other dialogs. This will install an entry named
Compare with Notepad++in the Explorer context menu of all files. After that you can delete the *.reg file, it is no longer needed.
Now close Notepad++. Open an Explorer window, right-click one file, select
Compare with Notepad++from the context menu, right-click another file and do the same. Notepad++ should open and the files should be compared by the
Close Notepad++ again. Select two files at once, right-click one of them and select
Compare with Notepad++from the context menu. Notepad++ should open and the files should be compared by the