Record a macro that's just the pasted text?
-
I’d like to generate macros that are just a bunch of pre-existing text, with the cursor in a specific place when it ends. This was working well, until I copied something new, and I learned that ‘ctrl-v’ was macro’d instead of the contents of the paste!
Is there any simple way to accomplish this without manually typing out the whole thing (preferably without having to code in the macro, but I can imagine that might be necessary.)
-
So I think what you really want to do is record a macro of typing specific text at the cursor, rather than pasting… but you don’t want to actually have to type it while recording the macro. In that case, you will either have to type all the text instead of pasting, or edit the macro after it’s recorded.
- record the macro where you do all your other stuff, but instead of pasting, type something easy to type (maybe just an
A
), and save the macro - exit notepad++ (which saves the macros to the config file)
- edit
%AppData%\Notepad++\shortcuts.xml
(🛈) - look in
shortcuts.xml
for the name of your macro. It should have more than one<Action ...>
line where themessage="2170"
– when you record a macro, it uses one Command for each letter… but when you manually edit the macro, it can have multiple characters. So if you only have one 2170, you could change it from
to<Action type="1" message="2170" wParam="0" lParam="0" sParam="A" />
I used<Action type="1" message="2170" wParam="0" lParam="0" sParam="Multiple Words Here" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="
" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="... and more here" />


for embedding a newline inside thesParam
- Save the
shortcuts.xml
- Exit Notepad++ and restart.
- Now the macro will use your edited text when it “types”, rather than the
A
that I had you record, or the Edit>Paste/Ctrl+V
that you previously recorded
As an alternate to steps 1-4, if you already have the macro recorded with the
Ctrl+V
/Paste, then you can eidtshortcuts.xml
directly (as described above) and look for<Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
which is the Paste command. Replace that with one or more of the 2170 as shown above, and save and exit/restart, and it will do the same thing.
- record the macro where you do all your other stuff, but instead of pasting, type something easy to type (maybe just an
-
@PeterJones Thanks, I went ahead and wrote a python script to help automate this process, and I’m including it here for anyone else that might need it in the future. This really seems like something that would be best implemented as part of np++ with something like shift+ctrl+v to use the pasted output rather than memorizing ctrl+v.
#Line commands found here: https://github.com/notepad-plus-plus/notepad-plus-plus/blob/af56713079c9e31b8c81b5603a6c841afb3e2005/scintilla/include/Scintilla.h cursorLine = 5 #On what line do you want to end up at (0 indexed)? Enter -1 to leave it at the end. pastedInput = \ '''#include <bits/stdc++.h> using namespace std; int main(){ return 0; }''' pastedInput = pastedInput.replace('"','"') #don't conflict with np++ macro syntax newline = '\n\t\t\t<Action type="1" message="2170" wParam="0" lParam="0" sParam="
" />\n\t\t\t<Action type="1" message="2170" wParam="0" lParam="0" sParam="
" />' out = [f'\t\t\t<Action type="1" message="2170" wParam="0" lParam="0" sParam="{line}" />{newline}' for line in pastedInput.split("\n")] linesUp = len(pastedInput.split("\n")) - cursorLine if cursorLine > 0: out.extend(['\t\t\t<Action type="0" message="2302" wParam="0" lParam="0" sParam="" />' for i in range(linesUp)]) #line up out.append('\t\t\t<Action type="0" message="2314" wParam="0" lParam="0" sParam="" />') #line end print("\n".join(out))
-
@eeegnu00 said in Record a macro that's just the pasted text?:
This really seems like something that would be best implemented as part of np++ with something like shift+ctrl+v to use the pasted output rather than memorizing ctrl+v.
I’m struggling to understand this part. Hmm.
-
@Alan-Kilborn As in:
Macro with ctrl-v on a replay: type in control v and use what’s currently in the copy buffer.
Macro with ctrl-shift-v on a replay: use what was in the copy buffer at the moment it was used when recording the macro. -
@eeegnu00 said in Record a macro that's just the pasted text?:
really seems like something that would be best implemented as part of np++ with something like shift+ctrl+v to use the pasted output rather than memorizing ctrl+v
The macro recorder basically records keystrokes and menu clicks. If you type
Ctrl+V
or use the Paste menu entry, it will record that command.Since you seem to know Python, I will
reiteratebring up that there’s a plugin called PythonScript which embeds a Python interpreter in Notepad++, and gives that interpreter access to the Notepad++ GUI commands (including the ability to open new files, create new files, etc) and editor commands/keystrokes, along with being a fully functional Python interpreter. Anything you can do in a macro, you can do in PythonScript; anything† you can do in Python, you can do in PythonScript. I rarely use Macros, because anything that I think of to do in macros, I am more likely to want one of the advanced features found in PythonScript (looping, variables, etc).†: just about anything. it’s harder to install modules in the PythonScript instance, since pip isn’t available for it; other than that. I don’t know of anything else that cannot be done.
-
@PeterJones said in Record a macro that's just the pasted text?:
Anything you can do in a macro, you can do in PythonScript
Definitely note that the converse is not true…macros are very limiting.