Comparing and editing files
-
Hey, I have 2 versions of a file and with the ComparePlus plugin I was able to find what I needed i.e. changed and added unique lines, however I haven’t been able to find a way to copy the new/changed lines. The plugin marks them visually, but couldn’t find a way to search/mark or copy them.
On the left is the old file and on the right the new file.
-
I don’t know of a way using only Notepad++. I can suggest the free and open source program WinMerge. Compare the two files, select View | Diff Context | 0 Lines and you will see only the lines that are different. Click in the side you want to copy, select all and copy (Ctrl+A then Ctrl+C); you can then paste the result into a new Notepad++ tab.
-
I don’t think ComparePlus has a “copy all diffs” or similar command. But you can use the Next/Previous buttons in the ComparePlus section of the toolbar to navigate to the next difference, and then you can copy that line or lines yourself.
If you only want to view the lines that are different, you can use Plugins > ComparePlus > Show Only Diffs (or the ShowOnlyDiffs button next to the “Last” button on the toolbar), but unfortunately, even if it only shows the differing lines, it will still copy all the lines (even the hidden ones) with a
Ctrl+A, Ctrl+C
.But if you’re doing an All, do you really need them marked or copied? The only benefit of marking is visual, and you already get that in ComparePlus. The benefit of Bookmarking would be for easy navigation to next/previous difference, but again, you already get that in ComparePlus through the navigation buttons. If you Copy everything and paste it in the other window, it will make the left file look like the right file, in effect copying over all the differences, leaving anything that was the same still the same, so I don’t see a benefit to just Copying the differences without copying the context. (I do think I probably had a feature request for the old Compare plugin [the precursor to ComparePlus] to allow a
diff
style difference-report to be exported somehow, but I believe I was told that Compare/ComparePlus work differently under the hood, so that old-stylediff
report wasn’t easy/convenient, and wouldn’t be implemented; but I could be mis-remembering [I do that a lot])Workaround or alternatives aside, most compare-tools I’ve used have some “merge” features as well as having the compare features. Glancing at the open issues/requests for the ComparePlus plugin, I don’t see any that immediately look like someone’s asked @pnedev for the “merge”-style features from other compare/merge-tools, but it would be a reasonable feature request for the plugin – and I’d definitely use such a feature if it existed. I really like that in TortoiseDiff/TortoiseMerge (which I use for TortoiseSVN version control), you get the ability to “Use Left Block” or “Use Right Block” (in diff, and even some “use both block” options in Merge), and have it move the appropriate text from left to right or right to left into the other view, so that way you can apply the changes to make the files more similar, in whichever direction is appropriate, without manually having to do the copy/paste.
-
@Coises said in Comparing and editing files:
I don’t know of a way using only Notepad++. I can suggest the free and open source program WinMerge. Compare the two files, select View | Diff Context | 0 Lines and you will see only the lines that are different. Click in the side you want to copy, select all and copy (Ctrl+A then Ctrl+C); you can then paste the result into a new Notepad++ tab.
I tried it, but I only want the 1206 added and 60 changed files and i wasn’t able to make Winmerge differentiate in the way that ComparePlus differentiates them which would be perfect. It shows me thousands of differences when I know there are only 1266.
@PeterJones said in Comparing and editing files:
If you Copy everything and paste it in the other window, it will make the left file look like the right file, in effect copying over all the differences, leaving anything that was the same still the same, so I don’t see a benefit to just Copying the differences without copying the contex
For what I’m doing I would need to be able to have all the old lines and the new lines in the same file while being separate e.g.
-
@JukeStuff The lines have markers so can identify the wanted lines by the markers.
With the PythonScript plugin:
# https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript/1 from Npp import editor, editor1, editor2, notepad def main(): # ComparePlus v1.1.0 defined markers LINE_CHANGED = 0x21 LINE_ADDED = 0x82 total = '' for index, editor_id in enumerate((editor1, editor2), 1): total += '<!-- FILE: {} -->\n'.format(index) for line in range(editor_id.getLineCount()): marker = editor_id.markerGet(line) if marker: marked = False if marker & LINE_CHANGED == LINE_CHANGED: marked = True if marker & LINE_ADDED == LINE_ADDED: marked = True if marked: text = editor_id.getLine(line) total += '{}'.format(text) notepad.new() editor.addText(total) main()
Make sure the 2 compared documents are shown in the 2 panes before running the script. The script will open a new document with the results.
The
markerGet
method gets the markers for a line. Printmarker
name to get the value if the defined markers do not match up with your Notepad++/ComparePlus setup. -
Hello @JukeStuff ,
I don’t know if I’ve understood your query correct but:
-
If you want to copy only the diffs from one compared file you could get the latest development build of ComparePlus from here: Win 32-bit / Win 64-bit (please use the correct DLL for your Notepad++ variant) and you need to install that development build manually (let me know if you need instructions for that). Then after comparing the files switch to the file which diffs you want to copy, then go to the ComparePlus submenu in Notepad++'s Plugins menu and from there choose the new command
Bookmark All Diffs in Current View
. This will put a bookmark on every line that is different. After that go to Notepad++'s menuSearch
-> theBookmark
submenu near the very bottom. From there you could choose what to do with the bookmarked lines. One of the operations isCopy Bookmarked Lines
. This way you could copy all lines that differ in the file. If you need to do that often then you could always assign custom shortcuts to both ComparePlus commandBookmark All Diffs in Current View
and Notepad++ commandCopy Bookmarked Lines
and use them in the future (again, if you need help assigning the shortcuts please write here). To automate the process further you can probably even create a Macro for that but I haven’t played with that Notepad++ functionality so I cannot help you with that (other users here could guide you how to do this). -
If you’d like to achieve what @PeterJones suggests then ComparePlus actually has merge possibilities (those are a bit obscured unfortunately because the ComparePlus submenu is already a bit crowdy). To merge some diff blocks (that is to copy one block from the left file and place it on the right or vice versa) then after compare switch to the file that you want to edit (that is in which you want to copy a diff block from the other file). Then exactly where the diff block is to be merged (the diff blocks between files are aligned) you need to click with the left mouse button on the compare margin (where the diffs green + or red - signs are - even if there are no such signs) while holding
CTRL
key. I’m sorry if is sounds complicated but I do not know how to create a video of my desktop while doing it so I just had to give you a clue what to try. Play a bit with clicking the Compare margin with or without holding theCTRL
key and you could also try what happens while holding theSHIFT
key orCTRL
+SHIFT
together.
BR
-
-
-
-
Compare plugin in notepad ++ is fantastic for highlighting file difference, and multi edit makes it simultaneous changes easy.