Adding more steps to an existing Macro
-
@Terry-R said in Adding more steps to an existing Macro:
recreating the macro with additional steps,
Yes, I wish to add more steps to an existing Macro. I am using RegEx’s to alter the content.
-
@Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:
I wish to add more steps to an existing Macro
The presumption here is that you created the macro via macro recording.
No, there is no way to add to it, via recording.I am using RegEx’s to alter the content.
Another presumption is that you’ve recorded one replacement operation into your macro, and now you want to add more of those.
If so, then it is fairly easy to “hand-edit” the macro to include more such operations.- exit Notepad++ to make sure that it saves its current configuration
- make a copy of your
shortcuts.xml
file (in case something bad happens) :-) - restart Notepad++
- edit
shortcuts.xml
and locate your macro within it - note that there are a block of lines in the macro starting with
1700
and ending with1701
- copy and paste that block of lines at the end of the macro
- edit the (copied) lines that contain your search regex text and your replacement text, to conform to the new replacement operation that you want to add
- save
shortcuts.xml
- restart Notepad++
For much more detail, see the user manual page for this, HERE.
-
@Alan-Kilborn
My shortcuts.xml - I have 2 Macros - ParaTxt2Raw and RegExTest.
How do I find them?
<?xml version="1.0" encoding="UTF-8" ?> <NotepadPlus> <InternalCommands /> <Macros> <Macro name="Trim Trailing Space and Save" Ctrl="no" Alt="yes" Shift="yes" Key="83"> <Action type="2" message="0" wParam="42024" lParam="0" sParam="" /> <Action type="2" message="0" wParam="41006" lParam="0" sParam="" /> </Macro> </Macros> <UserDefinedCommands> <Command name="Get PHP help" Ctrl="no" Alt="yes" Shift="no" Key="112">https://www.php.net/$(CURRENT_WORD)</Command> <Command name="Wikipedia Search" Ctrl="no" Alt="yes" Shift="no" Key="114">https://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD)</Command> <Command name="Open selected file path in new instance" Ctrl="no" Alt="yes" Shift="no" Key="117">$(NPP_FULL_FILE_PATH) $(CURRENT_WORD) -nosession -multiInst</Command> </UserDefinedCommands> <PluginCommands /> <ScintillaKeys /> </NotepadPlus>
—
moderator added code markdown around text; please don’t forget to use the
</>
button to mark example text as “code” so that characters don’t get changed by the forum -
@Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:
How do I find them?
You probably need to open
%AppData%\Notepad++\shortcuts.xml
, which is the active copy of that file, not the one in your installation directory (which is the one I guess you opened) -
@PeterJones said in Adding more steps to an existing Macro:
%AppData%\Notepad++\shortcuts.xm
You nailed it, Thanx a bunch
-
@PeterJones
Are comments allowed in shortcuts.xml? -
@Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:
@PeterJones
Are comments allowed in shortcuts.xml?Allowed, yes. Preserved, I don’t think so. If you record a new macro or do anything else in the GUI that affects that file (create a run menu entry, or change shortcut in Shortcut Mapper), I seem to remember that it will rewrite the file without your comments.
I have sometimes used the string attribute on a command that doesn’t use it to create a pseudo-comment in a macro… You can search the forum for my posts about macros, and can probably find an example with pseudo-comments.
-
@PeterJones
OK NOW. I removed the shortcuts.xml file, Stopped/Started Notepad++. It made a new. I modified and it appears to work.
Thanx for all the help. This will be so handy!Sorry for not marking code. I will going forward.
I cloned and changed the shortcuts.xml.
Than stopped/started Notepad++
It does not recognize the new file.
After changes to the file, or a new file copied in, the Macros I can see in the file are no longer available.
<?xml version="1.0" encoding="UTF-8" ?> <NotepadPlus> <InternalCommands /> <Macros> <Macro name="Trim Trailing Space and Save" Ctrl="no" Alt="yes" Shift="yes" Key="83"> <Action type="2" message="0" wParam="42024" lParam="0" sParam="" /> <Action type="2" message="0" wParam="41006" lParam="0" sParam="" /> </Macro> <Macro name="ParaTxt2Raw2" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="\\id.*?\\p" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="\\c 1" /> <Action type="3" message="1702" wParam="0" lParam="1794" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="\\[a-z][\s|\r\n]" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1702" wParam="0" lParam="1794" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="\r\n\n" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="\r\n" /> <Action type="3" message="1702" wParam="0" lParam="770" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro> </Macros> <UserDefinedCommands> <Command name="Get PHP help" Ctrl="no" Alt="yes" Shift="no" Key="112">https://www.php.net/$(CURRENT_WORD)</Command> <Command name="Wikipedia Search" Ctrl="no" Alt="yes" Shift="no" Key="114">https://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD)</Command> <Command name="Open selected file path in new instance" Ctrl="no" Alt="yes" Shift="no" Key="117">$(NPP_FULL_FILE_PATH) $(CURRENT_WORD) -nosession -multiInst</Command> </UserDefinedCommands> <PluginCommands /> <ScintillaKeys /> </NotepadPlus>
—
moderator added code markdown around text; please don’t forget to use the
</>
button to mark example text as “code” so that characters don’t get changed by the forum -
@Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:
After changes to the file, or a new file copied in, the Macros I can see in the file are no longer available.
It works for me. I pasted your example into my active shortcuts.xml file, saved, exited Notepad++, and restarted, and it saw the new macro just fine.
Are you sure you did things in the right order? The User Manual describes the order of events you must follow if you want to edit a Notepad++ config file with Notepad++ – you have to exit Notepad++ (to make sure that all the changes Notepad++ has queued up are written), then start Notepad++, then do the manual edit, then save and exit (without doing any changes in the GUI) then restart. If you don’t follow that order, Notepad++ will overwrite your changes (if there had been any GUI changes that affect that file) when it exits,
-
@Robert-Or-Janet-Diebel said in Adding more steps to an existing Macro:
Are comments allowed in shortcuts.xml?
You can do this:
<Action type="1" message="2172" wParam="0" lParam="0" sParam="I am a comment!!!!!!!!" />