How to get an external "diff" viewer, with N++ and the last "Compare" plugin, "v2.0.0.0"...
-
Hi, All,
I was comparing two files, with the last
v2.0.0.0
version of the excellentCompare
plugin of Pavel Nedev, ( alias @pnedev ), when I, suddenly, remembered that, in a prior version, it was possible to emulate adiff
viewer ! After investigation, looking in my plugins backups, this tool is, indeed, available from theComparePlugin.v1.5.6.6.bin.zip
archive ( and, probably, from versionv1.5.6.7
, too ! )And, in the change.log file, it is said :
v1.5.6.6 : 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 theComparePlugin_v2.0.0_X64.zip
, archive, too ), which can, both, be downloaded from :https://github.com/pnedev/compare-plugin/releases/tag/v2.0.0
So, I did a test to verify if that tool could be associated with the Compare plugin, version
2.0.0.0
and 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
v2.0.0.0
is already installed, on your current N+++ configuration. So :- 1) Download the
1.5.6.6.
version of the Compare plugin, from that link :
https://bitbucket.org/uph0/compare/downloads/ComparePlugin.v1.5.6.6.bin.zip
-
2) From the ComparePlugin folder of that archive, extract the two files,
compare.exe
andcompare.ini
, only :-
In the folder
%AppData%\Notepad++\plugins\ComparePlugin\ComparePlugin
, along with the two librariesgit2.dll
andsqlite3.dll
, if you previously installed Notepad++, with the Installer -
In folder
<N++ installation> folder\plugins\ComparePlugin\ComparePlugin
, along with the two librariesgit2.dll
andsqlite3.dll
, if your installation of N++ was a local installation, from a7z
orzip
archive, in any folder
-
Remarks :
This post has been updated in order to mention the new architecture of plugins, since Notepad++ version
v6.0
and aboveIn case of a local N++ installation, these two files
compare.exe
andcompare.ini
may, 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.ini
file, by adding, in the[Notepad]
section, the line :
path=<ABSOLUTE path of Notepad++>\notepad++.exe
Notes :
The environment variables, as, for instance,
%PROGRAMFILES(X86)%
or%USERPROFILE%
and/or the special directories.
and..
can be used to constitute the absolute pathNO 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
cmd
command -
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_A
andFile_B
files, already compared ;-))Notes :
-
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
Best Regards,
guy038
- 1) Download the
-
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
Plugins
menu in the locale your Notepad++ UI is set to.The code checks if there is an environment variable
NppCommand
with the valueCompareFiles
. 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
Save...
and enterCompareFilesOnStartup
into the combo box. This is the name the script can be called with. Then click theSave
button and close the dialog by clicking theOK
button.Now navigate to
(menu) Plugins -> NppExec -> Advanced Options...
and select in the combo box underExecute this script when Notepad++ starts
theCompareFilesOnStartup
script you created above. Close the dialog by clicking theOK
button.The Controlling Batch Script
Open a new file in Notepad++ and paste the code below into it. Store it as
NppCompareFiles.cmd
.@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 /p
command 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
NppCommand
is created and set to the valueCompareFiles
(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 thestart
command 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
NppCompareFilesLauncher.vbs
.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.cmd
script 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
NppCompareFiles.cmd
andNppCompareFilesLauncher.vbs
to a folder of your choice. For this How-To I will useC:\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.
"
and\
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.First Try
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 theCompare
plugin.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 theCompare
plugin.