Copy and paste between two files
-
Hey. I would need to make some macro that copies a selected line and pastes it to the same place in a second document, if I have them open in side by side windows. It doesn’t have to be on the same line number though, just a synchronized vertical scrolling. Is something like this possible?
-
The View > Focus on another View command (which defaults to F8) is what allows you to swap from one view to the other… Unfortunately, it is not macro-recordable. Fortunately, it is macro-playable, so you can record a temporary macro and save it (which just has copy and paste), restart Notepad++, open
%AppData%\shortcuts.xml
, find that macro (I called itCopyViewPasteView
), and add the lines to issue 44072 (which is the command ID for View > Focus on another View<Macro name="CopyViewPasteView" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="44072" lParam="0" sParam="" /> <Action type="0" message="2179" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="44072" lParam="0" sParam="" /> </Macro>
After saving
shortcuts.xml
, restart Notepad++. Now that macro will be in the Macro menu, and will do the “copy, F8, paste, F8” sequenceYou might think my figuring that out was “magic”, but really, it is just making use of the information available to everyone through the user manual (and enough experience to know that, while not all actions are recordable, more are playable than recordable).
You can use the Macro > Modify Shortcut/Delete Command interface to assign a single keystroke to that macro.
-
@PeterJones
Thank you for your help. This seemed like a very good idea, however what is happening to me is that the right document is still inserting the line in the same place (same line) and not on the opposite line.<Macro name="CopyAndPaste" Ctrl="no" Alt="yes" Shift="yes" Key="73"> <Action type="0" message="2453" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2452" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="44072" lParam="0" sParam="" /> <Action type="0" message="2453" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2452" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2179" wParam="0" lParam="0" sParam="" /> <Action type="2" message="0" wParam="44072" lParam="0" sParam="" /> </Macro>
-
@Martin-Steiner said in Copy and paste between two files:
the right document is still inserting the line in the same place (same line) and not on the opposite line.
Sorry, your spec was rather unclear. In that you said “it does not have to be on the same line”, which I thought meant that you just wanted it to go someplace on the right, not that the one on the right had to be the same line number as the source on the left.
Macros don’t have the capability to know what line number you were on in the source pane or in the destination pane, and no way to do the variable manipulation to navigate the right number of lines relative to where you currently are or anything like that.
if you had a well-defined procedure (which you haven’t given us), it would be doable in a full scripting plugin like PythonScript, which could do all the line number and copy/paste actions necessary for any task similar to what you describe; but that requires knowing Python.
But it looks like what you’re really doing is comparing two files, and trying to make the right file look more like the left file. To do that, I would say: install the Compare plugin, which will mark the lines on the left as “missing” from the right, and it has features that can then copy each “missing” block and paste them in the equivalent location on the right. Based on your example screenshots, I think that’s what you want.
-
@PeterJones
I guess we didn’t understand each other. It doesn’t have to be on the same line number, but I would need it to be on the same horizontal line. Anyway, thanks for your help. -
“To be on the same horizontal line” is not something that a macro can make it do, as it is essentially the same problem as “on the same line number” (or maybe even more complicated).
As I said, give Compare Plugin a try; I think it will accomplish your goal: it will line up the existing lines of text, so that things that match from one to the other will be lined up; and it will show the differences where they don’t match, and allow you to choose which of those differences to propagate from one to the other.
If that doesn’t work, you’ll either have to download a scripting plugin like PythonScript (or LuaScript, or one of the others) and know how to do enough in that underlying language to implement the feature yourself, or you will have to live without the automation and just manually find the places like you currently do.
-
@PeterJones
OK, I’ll try it. Thank you.