HELP: Having trouble with Macros in v8.5.3 or later
-
@Grath777 said in HELP: Having trouble with Macros in v8.5.3 or later:
I am doing find/replace in Regular Expression mode where the find and replace fields also both include a tab character which we define in the macro thusly
Searching for or replacing a tab character in a Regular Expression doesn’t need to have the tab character encoded like that: you can use the regular expression syntax
\t
in both the Find What and Replace With fields and have it work. So in your macro source, where you had a	
in a search or replace field (so in thesParam="..."
of themessage="1601"
for Find What and in thesParam="..."
of themessage="1602"
for Replace With, per Search and Replace Macros in the User Manual), you could just use a\t
instead, which will avoid all the macro issues. -
-
@PeterJones I have a macro which inserts a new line:
<Action type="1" message="2170" wParam="0" lParam="0" sParam="
" />
<Action type="1" message="2170" wParam="0" lParam="0" sParam="
" />


gets inserted literally instead of a new line (CR/LF) with version v8.5.3. I tried to use “\n” instead but this gets inserted literally too. What am I doing wrong? -
So I have found the solution (thanks to @PeterJones) in the FAQ:
Find what:
Replace With:\x{000D}
Find what:

Replace With:\x{000A}
with Search mode set to Regular Expression and run Replace All. -
Hello, @datatraveller1, @peterjones and All,
@datatraveller1, I do not think that your macro really adds a line-break when you use the
\x{000D}
and\x{000A}
syntax in the<Macros>
node of yourshortcut.xml
file, inN++ v8.5.3
Personally, adding the following section, in my portable N++
v5.8.3
installation :<Macro name="ABC + Line-Break" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="1" message="2170" wParam="0" lParam="0" sParam="A" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="B" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000D}" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000a}" /> </Macro>
Results, when running this macro in a new tab, by the insertion of the literal text
ABC\x{000D}\x{000A}
Whereas, selecting the string, between the double-quotes of the
sParam
attribute, and :-
Hitting the
ALT
key and, pressing simultaneously the0
,1
and3
keys, on the numeric keypad, does insert a trueCR
character -
Hitting the
ALT
key and, pressing simultaneously the0
,1
and0
keys, on the numeric keypad, does insert a trueLF
character
In the last two lines
Action
of the macro and gives this text :<Macro name="ABC + Line-Break" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="1" message="2170" wParam="0" lParam="0" sParam="A" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="B" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="C" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " /> <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " /> </Macro>
IMPORTANT : If you paste this text in a new tab, don’t forget to change the line-break of two last lines with
CR
andLF
, instead of keeping twoCRLF
lines !Just select the two chars
CRLF
of the last two lines and use theALT
+ numeric keypad method to change the first line-break asCR
and the second one asLF
. Delete any non-intentional leadingTAB
chars, too.
Running this last version of the macro does write the
ABC
string followed with a Windows line-breakCRLF
;-))My debug info :
Notepad++ v8.5.3 (64-bit) Build time : May 15 2023 - 06:09:36 Path : E:\853_x64\notepad++.exe Command Line : Admin mode : OFF Local Conf mode : ON Cloud Config : OFF OS Name : Windows 10 Pro (64-bit) OS Version : 22H2 OS Build : 19045.2965 Current ANSI codepage : 1252 Plugins : mimeTools (2.9) NppConverter (4.5) NppExport (0.4)
Best Regards,
guy038
-
-
Hi @guy038 thank you, CR and LF got inserted as real line breaks with the FAQ solution:
-
I am having that kind of trubble my self too. I am getting errors of encoding in simple strings with accents for example with the use of the following caracters: à ù ò.
Please have a look at the following picture:Maybe the new implementation is not yet complete.
Thank for reading.
-
Hello, @wonkawilly and All,
Finally, @wonkawilly, here is the right way to enter any character according to the new behaviour of macros, in N++
v.8.5.3
!
-
Open your active
shortcuts.xml
file in Notepad++ -
Insert the empty template, below, at the end of the Macros section, right before
</Macros>
, in yourshortcuts.xml
file :
<Macro name="Test" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="1" message="2170" wParam="0" lParam="0" sParam="" /> </Macro>
- Duplicate the line
<Action type="1" message="2170" wParam="0" lParam="0" sParam="" />
, as many times as the number of chars to be inserted, incuding a possible line-break, with theCtrl + D
shortcut
=> In your exemple, we’ll add four lines
<Macro name="Test" Ctrl="no" Alt="no" Shift="no" Key="0"> <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="1" message="2170" wParam="0" lParam="0" sParam="" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="" /> </Macro>~~~
-
Put your caret/cursor between the two double-quotes of each
sParam
attribute -
Open the
Edit > Character Panel
menu option -
Double-click on the characters to insert, located under the ‘Character’ column of the
Character Panel
. Thus, for the line-break chars, just double-click onCR
, thenLF
!
=> We get this functional macro :
<Macro name="Test" Ctrl="no" Alt="no" Shift="no" Key="0"> <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="1" message="2170" wParam="0" lParam="0" sParam=" " /> <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " /> </Macro>
-
Save your
shortcuts.xml
file -
Close and restart N++
Enjoy your
Test
macro !Best Regards,
guy038
-
-
@guy038 said in HELP: Having trouble with Macros in v8.5.3 or later:
here is the right way to enter any character according to the new behaviour of macros, in N++ v.8.5.3!
The right way became a little bit more cumbersome than before… I rather like to write whole string with the keyboard or even better by voice.
I have to say that if there is a thing that I really hate about N++ since the first usage is the macro system. I would like to see it replaced with a better language for example js, py, cs or else, keeping the capability to record commands executed into N++ and adding the possibility to modify a macro written into a real and serious programming language that is easily human readable and modifiable than the macro system actually implemented that is really ugly.
-
@wonkawilly As far as I have understood @guy038 and the FAQ, you simply have to replace the old values UTF-8 encoded literally with
è
,à
etc.I’m not sure if something like Python would work for the macro system but I partly agree that it is a bit ugly sometimes - In my case I don’t like that real line breaks get inserted into shortcuts.xml.
-
Hi, @wonkawilly, @datatraveller1 and all,
But, of course, if a character is available on your keyboard, you may, as well, just type in this character !!
It’s only for special chars as line-break chars and some others that you need the help of the
Character Panel
For instance, for the line-break chars, just use the method, described in my post to @datatraveller1, using
ALT
+013
andALT
+010
, on the numeric keypadBR
guy038
P.S :
@datatraveller1, The best when creating macros is to open the
Character Panel
, first and :-
Double-click on [
CR
and ]LF
, each time you want to insert a line-break in a macro -
Double-click on any character when this char is not available on your keyboard !
-
-
Certainly copy and paste of a character from another source also works fine as an alternative to using the Character Panel, which has a limited number of possible characters anyway.
But, as stated, probably Character Panel is a good choice for carriage-return and line-feed characters.
-
I was going back through some of the posts here, to see if there are improvements that can be made to the FAQ.
I do not think that your macro really adds a line-break when you use the \x{000D} and \x{000A} syntax in the <Macros> node of your shortcut.xml file, in N++ v8.5.3
I think you misread @datatraveller1: you seemed to asssume he changed to the literal
<Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000D}" /> <Action type="1" message="2170" wParam="0" lParam="0" sParam="\x{000A}" />
If that had been the case, it wouldn’t work. But based on the “find what” and “replace with” in the post you replied to, he actually followed the advice found in the FAQ, which is when editing
shortcuts.xml
to use Notepad++ Replace window to run a regex search-and-replace. Using the “find what” and “replace with” that @datatraveller1 mentioned, and which I suggested in the FAQ, will change the
sequence to the actual CR character and

with the actual LF character.Later, @guy038 also wrote:
Duplicate the line
<Action type="1" message="2170" wParam="0" lParam="0" sParam="" />
, as many times as the number of chars to be inserted, including a possible line-break, with the Ctrl + D shortcutThere’s no need. The macro recorder just puts one character per
2170
-message, but that’s not a restriction of the macro playback. If you are editing a macro and want to insert the textèòù[CRLF]
, the single action<Action type="1" message="2170" wParam="0" lParam="0" sParam="èòù " />
will work (assuming the linebreak in the sParam is really a CR and LF)
That said, based on what I’ve re-read here, I will suggest the
Alt
+013
andAlt
+010
methods of entering those characters, and using the Character Panel (or Run > Run… >charmap.exe
) for entering characters that aren’t on your keyboard. -
Hello, @wonkawilly, @datatraveller1, @alan-kilborn and all,
Oh… Of course, I forgot to mention that, in my previous posts, I refered to macros already created by a user with a N++ version prior to
v8.5.3
!If, with N++
v.8.5.3
, you just create a new macro, containing one or several line-break(s), it’ll be correctly recorded !However, I noticed some oddities when recording these line-breaks !
Follow these different actions for testing :
-
Open N++
v.8.5.3
-
Open a new tab
-
If the line-break format of the new tab is not
Windows (CR LF)
, in the status bar, change it with the commandEdit > EOL Conversion > Windows (CR LF)
-
Start recording a macro with the command
Macro > Start Recording
-
In the new tab, just type in the string
ABC
and hit theEnter
key -
Then, type in the string
DEF
and hit , again, theEnter
key -
Stop recording the current macro with the command
Macro > Stop Recording
-
Click on the the menu option
Macro > Save Current Recorded Macro...
-
Give the name
Test_CRLF
to this macro -
Delete all contents of this new tab with a
Ctrl + Z
operation -
Change the EOL format of the new tab to Unix, with the command
Edit > EOL Conversion > Unix (LF)
-
Start recording a macro with the command
Macro > Start Recording
-
In the new tab, just type in the string
GHI
and hit theEnter
key -
Then, type in the string
JKL
and hit , again, theEnter
key -
Stop recording the current macro with the command
Macro > Stop Recording
-
Click on the the menu option
Macro > Save Current Recorded Macro...
-
Give the name
Test_LF
to this macro -
Delete all contents of this new tab with a
Ctrl + Z
operation -
Change the EOL format of the new tab to Mac, with the command
Edit > EOL Conversion > Macintosh (CR)
-
Start recording a macro with the command
Macro > Start Recording
-
In the new tab, just type in the string
MNO
and hit theEnter
key -
Then, type in the string
PQR
and hit , again, theEnter
key -
Stop recording the current macro with the command
Macro > Stop Recording
-
Click on the the menu option
Macro > Save Current Recorded Macro...
-
Give the name
Test_CR
to this macro -
Close N++
v.8.5.3
, without saving the new tab -
Restart N++
v.8.5.3
-
Open your active
shortcuts.xml
file -
Note the contents of the three macros
Test_CRLF
,Test_LF
andTest_CR
:-
In the
Test_CRLF
macro, the first part of each EOL recording is theCR
character ( OK ) but the second part isCRLF
and notLF
( ?? ) -
In the
Test_LF
macro, the two EOL recording are theCRLF
characters and not theLF
chars ( ?? ) -
In the
Test_CR
macro, the two EOL recording are correctly theCR
characters ( OK )
-
I don’t know, if we should trigger an
GitHub
issue for these oddities ??Best Regards
guy038
P.S. : I’ve just seen the @peterjones’s post… and will have a look at it !
-
-
@guy038 said in HELP: Having trouble with Macros in v8.5.3 or later:
Note the contents of the macros Test_CRLF , Test_LF
I can duplicate your poor results with these two. :-(
if we should trigger an GitHub issue for these oddities ??
Either that, or post about it in the 8.5.3 release thread, HERE.
-
-
I’ve a similar problem.
I’ve created a macro doing a lot of things, included changing “word” into ‘word’ (look for ‘ ’ instead of " ").
This worked ok until last update (8.5.3, build May 15 2023 06:07:16).
Now the macro (I don’have touched it) change “word” into& # x 2 0 1 8 ; w o r d & # x 2 0 1 8 ;
Please ignore spaces: if I don’t insert spaces, this forum convert “& # x 2 0 1 8 ; w o r d & # x 2 0 1 8 ;” into " ‘word’ " and it’s impossible to understand what I mean.
I need Notepad++ don’t “convert” the ‘ ’ symbols.I’ve tried to search my macro recorded but I don’t find it in shortcuts.xml. Where I can find it? My macro is called “calcio (prime correzioni)” but in shortcuts.xml I find only “Trim Trailing Space and Save”. BTW the date of shortcuts.xml is from 2021 and maybe my macro was created after.
-
Hello, @massimo-piscopo and All,
I suppose that you have a standard installation with N++ installer ! Then, you must look for the real location of your
shortcuts.xml
file !
Follow the steps, below :
-
Open your Notepad++
v8.5.3
, as usual -
Click on the
Windows Logo
key and, simultaneously, hit theR
key -
In the Execute window, type in
Explorer.exe
and hit theEnter
key
=> The File Explorer program should start
-
Clic on the ‘STAR’ and type in the string
%appdata%\Notepad++
-
Valid with the
Enter
key
=> You should normally see a
shortcuts.xml
file, along with some others files- Clic on the
shortcuts.xml
file and drag this file into your notepad++ window
=> You should see, in the
<Macros>
section, your macro namedcalcio (prime correczioni)
-
Now, open the Replace dialog (
Ctrl + H
) -
Untick all box options
-
SEARCH
‘
-
REPLACE
\x{2018}
-
Check the
wrap around
option -
Select the
Regular expression
search mode ( IMPORTANT ) -
Click on the
Replace All
button -
Save the changes of your
shortcuts.xml
file -
Close Notepad++
-
Restart Notepad++
=> Your macro should be OK and do what it is designed for :-)
Best Regards,
guy038
-
-
I don’t find it in
shortcuts.xml
It’s there, or your macro doesn’t exist when you exit Notepad++ and restart. Did you look in the right
shortcuts.xml
?If you had read the first post in this discussion, you would have seen the we asked you to supply your ?-menu’s Debug Info. Because you chose not to do so, we have to assume the location of your
shortcuts.xml
is in%AppData%\Notepad++\shortcuts.xml
, as @guy038 guessed while I was typing this. -
@guy038 and @PeterJones THANK YOU SO MUCH, I’ve solved. <3
-
@datatraveller1 said in HELP: Having trouble with Macros in v8.5.3 or later:
@wonkawilly As far as I have understood @guy038 and the FAQ, you simply have to replace the old values UTF-8 encoded literally with
è
,à
etc.I’m not sure if something like Python would work for the macro system but I partly agree that it is a bit ugly sometimes - In my case I don’t like that real line breaks get inserted into shortcuts.xml.
It should be good enough to see it replaced with “\r\n” as in regular expression syntax. Nevertheless, that solution would of course be good just to “survive”, not in the long run, because nevertheless the optimus would be to have a complete new macro system as in LibreOffice, MsOffice and so on. It would be a huge improvement even replacing the current macro system in npp with a new macro system based on AutoIt language and macro recorder.
The current macro system is too cryptic and too limited. Compare this row
<Action type=“1” message=“2170” wParam=“0” lParam=“0” sParam=“è” />
with its equivalent in a simple scripting language in which you can even do loops or if/else and so much more.
IMHO the current macro system in N++ is going old… and really needs retirement, better sooner than later…
Also another ugly thing is that n++ saves new recorded macros only on exit: it would be better to save new created macros on click on the Save Macro button so they could be edited without the need of restarting npp: other ugly and incomprehensible thing. -
Moving to the next bookmark does not work inside a macro. No matter where the cursor is, it will always go to a specific bookmark.