I would like to write a macro for Notepad++ which should replace char1, char2, char3 with char4, char5, char6, respectively.
9 Answers
Macros in Notepad++ are just a bunch of encoded operations: you start recording, operate on the buffer, perhaps activating menus, stop recording then play the macro.
After investigation, I found out they are saved in the file shortcuts.xml in the Macros section. For example, I have there:
<Macro name="Trim Trailing and save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
<Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
<Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
<Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
<Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
<Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
<Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
<Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
</Macro>
I haven't looked at the source, but from the look, I would say we have messages sent to Scintilla (the editing component, perhaps type 0 and 1), and to Notepad++ itself (probably activating menu items).
I don't think it will record actions in dialogs (like search/replace).
Looking at Scintilla.iface file, we can see that 2170 is the code of ReplaceSel (ie. insert string is nothing is selected), 2327 is Tab command, and Resource Hacker (just have it handy...) shows that 42024 is "Trim Trailing Space" menu item and 41006 is "Save".
I guess action type 0 is for Scintilla commands with numerical params, type 1 is for commands with string parameter, 2 is for Notepad++ commands.
Problem: Scintilla doesn't have a "Replace all" command: it is the task of the client to do the iteration, with or without confirmation, etc.
Another problem: it seems type 1 action is limited to 1 char (I edited manually, when exiting N++ it was truncated).
I tried some tricks, but I fear such task is beyond the macro capabilities.
Maybe that's where SciTE with its Lua scripting ability (or Programmer's Notepad which seems to be scriptable with Python) has an edge... :-)
[EDIT] Looks like I got the above macro from this thread or a similar place... :-) I guess the first lines are unnecessary (side effect or recording) but they were good examples of macro code anyway.
-
3this [wiki](http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Editing_Configuration_Files#.3CMacros.3E) article has a breakdown of the
attribute flags – Pete Jun 02 '11 at 17:15 -
btw, it DOES record dialog actions. I used the macro to find/replace several times in a document and it worked perfectly. It requires you to click OK after each find though. – Derek Mar 07 '12 at 20:46
-
1seems it's not saved in this file when you don't have a keyboard shortcut associated... – Bojan Bjelic Oct 01 '13 at 07:01
-
2@Pete, your wiki-link is "dead". I found [this wiki article](http://npp-wiki.iwi.me/index.php/Editing_Configuration_Files#.3CMacros.3E); possibly a relocated version of the one you found. – Superole Jan 27 '15 at 14:55
-
It isn't just SciTE. Notepad++ has Python scripting as well: http://npppythonscript.sourceforge.net/ – Jerry Jeremiah May 18 '16 at 00:12
-
The relocated version of the wiki-page is not available anymore either, but if you're looking for a list of available `wparams` (as in, the action that a macro executes), you can use Resource Hacker as mentioned in this answer, or checkout the [language files on Github](https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/installer/nativeLang/english.xml#L69) for a full list of wparam-compliant IDs – Mischa Rodermond Nov 02 '17 at 10:22
I found 'Python Script' plugin for Notepad++ more useful since with the plugin, I could write simple macros in the form of python and It has also got very good documentation and sample macros written in python as well. If you are quite comfortable with python, then I think 'Python Script' will provide justice. For more information, refer : http://npppythonscript.sourceforge.net/

- 191
- 1
- 2
-
I found I had to install Python Script 1.0.8.0 as the one installed by the plugin manager is buggy – slonik Jun 10 '16 at 09:50
-
Yes but it isn't possible to "record" actions done by the user and save them as macros as it is possible for example in ms word or excel that saves in vba. This is a real shame because python script is more powerful than notepad plus plus macro code that lacks of some "elasticity" and clearness when reading and correcting and customizing a macro. So python script plugin doesn't work as macro does. – willy wonka Aug 06 '19 at 21:54
I recorded a macro and I found it in %APPDATA%\Notepad++\shortcuts.xml. It looks like posted in the first post of this thread.
I use NPP Ver. 5.9.6.2 with Win7.

- 8,292
- 5
- 40
- 53

- 87
- 1
- 1
Posting more than 10 years after the OP, but I think that this is still a relevant question (it is for me, at least). Today, there is quite some information in the Notepad++ User Manual, relating to the OP's question:
- General Info about macros: https://npp-user-manual.org/docs/macros/
- General explanation about the language used is in the config files docs: https://npp-user-manual.org/docs/config-files/#macros
- Search and Replace Actions (as requested by the OP) are covered in more detail here: https://npp-user-manual.org/docs/searching/#searching-actions-when-recorded-as-macros
Here is a block of macro code: replace SEARCHTEXT by REPLACETEXT, using regular expressions, "." finds /r and /n, in every file matching the filter GLOBFILEFILTER in a folder PATH (no subfolders, not sure where this flag is defined/set).
<Macro name="REPLACE_IN_FILES_REGEX_DOT_FINDS_CR_AND_LF" 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="SEARCHTEXT" />
<Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
<Action type="3" message="1602" wParam="0" lParam="0" sParam="REPLACETEXT" />
<Action type="3" message="1653" wParam="0" lParam="0" sParam="PATH" />
<Action type="3" message="1652" wParam="0" lParam="0" sParam="GLOBFILEFILTER" />
<Action type="3" message="1702" wParam="0" lParam="1024" sParam="" />
<!-- #COMMENT: "1024" seems to be the flag ". finds /n and /r". This is not in the documentation. -->
<Action type="3" message="1701" wParam="0" lParam="1660" sParam="" />
</Macro>
Remarks about this code:
- The path to the folder needs to end with a backslash.
- Characters like <, >, & need to be escaped in the xml. Rather create your search and replace strings by recording a macro.

- 51
- 1
- 2
This post can help you as a little bit related :
Using RegEX To Prefix And Append In Notepad++
Assuming alphanumeric words, you can use:
Search = ^([A-Za-z0-9]+)$ Replace = able:"\1"
Or, if you just want to highlight the lines and use "Replace All" & "In Selection" (with the same replace):
Search = ^(.+)$
^ points to the start of the line. $ points to the end of the line.
\1 will be the source match within the parentheses.
My personal experience is that shortcuts.xml is overwritten with the initially loaded + later recorded macros and settings when Notepad++ exits. So you can't use Notepad++ itself for editing this file.
Close Notepad++, edit shortcuts.xml by another tool, save it and restart Notepad++.

- 623
- 7
- 11
I'm not sure if this helps, but I needed to create a macro to hold a snippet, so I simply recorded myself inserting the items and set a shortcut to it. Granted, I'm not using version 5.9 so there might be some slight version differences. To access the macro recorder go to Macro > Start Recording. Then you will perform your action and then go to Macro > Stop Recording. I'd recommend playing it back to ensure it's correct and then save and set your shortcut key.
Hope the helps.

- 1,070
- 15
- 26
I just did this in v5.9.1. Just go to the Macro Menu, click "Start Recording", perform your 3 replace all commands, then stop recording. You can then select "Save Current Recorded Macro", and play it back as often as you like, and it will perform the replaces as you expect.

- 6,768
- 25
- 40
Actually, the shortcuts.xml file does not store user-generated macros and no obvious candidates contain this info. These instructions are out of date.
Contrary to various websites' tips, storing user-generated macros isn't enabled for v.5.4.2. That XML file is there, but your macro does not get stored it in.
I'm guessing it's a bug that'll be fixed by the next version.

- 47
- 2
-
1
-
4
-
2They are stored in %userprofile%\Application Data\Notepad++\shortcuts.xml in 5.9.8. – Steve Rowe Mar 20 '12 at 04:52
-
I beg to differ - in 5.9 (Win7) user macros do indeed get stored in shortcuts.xml Note: they only get written there once you exit NPP. – Marc Nov 12 '12 at 19:41
-
In v6.6.7 you have the option to sync your settings to cloud, in which case you'll find them in ...\Dropbox\Notepad++\shortcuts.xml – harvest316 Aug 01 '14 at 11:46