How to achieve <bold>selection</bold>?
-
I wish when I press Ctrl + Shift + B, what I select will change into <bold>selection</bold>.
And I have failed a hundred times. I really have no idea what to do now.
Here is what I wrote,a Frankenstein.<Macro name=“<bold>” Ctrl=“yes” Alt=“no” Shift=“yes” Key=“66”>
<Action type=“1” message=“2287” wParam=“0” lParam=“0” sParam=“” />
<Action type=“1” message=“2190” wParam=“0” lParam=“0” sParam=“” />
<Action type=“3” message=“2001” wParam=“0” lParam=“0” sParam=“<bold>” />
</Macro>All help is appreciated… Thanks!
-
So if you select the text
Notepad++
and you invoke a macro you want that text to change into<bold>Notepad++</bold>
?For that I would record a macro consisting of one step, a replace-all operation.
Details:
Select some text to act upon.
Invoke the Replace dialog (Ctrl+h).
Set Find-what zone to:(?s).+
Set Find-what zone to:<bold>$0</bold>
Tick In selection checkbox
Set Search mode toRegular Expression
Start macro recording.
Press the Replace All button.
Stop macro recording.
Save macro, assign keycombo. -
Correction:
Set Find-what zone to:
<bold>$0</bold>
should be:
Set Replace-with zone to:
<bold>$0</bold>
-
Thanks for you help.
“So if you select the text Notepad++ and you invoke a macro you want that text to change into <bold>Notepad++</bold> ?”
Yes, but “the text” may contain anything, letters, words, spaces, numbers, tags, symbols. I don’t think “(?s).+” is enough.So, I need your further help if you don’t mind. [emoji (please)]
-
I can tell that you haven’t tried it.
HINT: Try it…or see the Clue below…
:-DClue : The regular expression
(?s).+
means “one or more characters with any value”. The$0
means whatever matched in the Find-what part, which in this case is the any-valued characters. -
I tried, but it keep alert “0 occurrences were replaced.”, should I ignore it and check shortcuts.xml?
-
And this is what I got in shortcut.xml
<Macro name=“test” 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=“(?s).+” />
<Action type=“3” message=“1625” wParam=“0” lParam=“2” sParam=“” />
<Action type=“3” message=“1602” wParam=“0” lParam=“0” sParam=“<bold>$0</bold>” />
<Action type=“3” message=“1702” wParam=“0” lParam=“640” sParam=“” />
<Action type=“3” message=“1701” wParam=“0” lParam=“1609” sParam=“” />
</Macro> -
Hello @liuruiqi1993, @scott-sumner and All,
I’ve just build the Scott’s macro, on my portable N++ v7.5.1 version. and it’s working fine, indeed :-))
In my shortcuts.xml file, inside the Macro section, these lines are added :
<Macro name="Test" 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="(?s).+" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="<bold>$0</bold>" /> <Action type="3" message="1702" wParam="0" lParam="640" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro>
The unique difference,compared to your version, it that the line :
<Action type="3" message="1602" wParam="0" lParam="0" sParam="<bold>$0</bold>" />
is written :
<Action type="3" message="1602" wParam="0" lParam="0" sParam="<bold>$0</bold>" />
I think that the later form should be the right one ! That is to say that the special characters
<
and>
, should be coded as<
and>
, in an XML file !BTW, note that, if you forget to select any range of characters, before running this macro, nothing changes, after execution. ( logical behaviour ) If it would, all the file contents would have been surrounded with the two tags <bold> and </bold> !
Cheers,
guy038
-
@guy038 and @scott-sumner
npp.5.9.4. version, NO. Then I tried npp.7.5.3. version, Yes, it’s working now, awesome!!
Thank you two, you helped a lot. And merry Christmas. -
Hello @liuruiqi1993 and All,
BTW, I advice you to downgrade to the
v7.5.1
version of Notepad++, because there are some encoding issues with the last two N++ versions ! See below :https://notepad-plus-plus.org/community/topic/14936/update-to-7-5-3-file-encode-wrong/2
Now, I understand why it did,'t work with your old
5.9.4
version. Just because, since the N++v.6.0
version, a new search engine is implemented, with the Perl Common Regular Expressions feature, of the Boost C++ regex library ! This new search engine allows you to run complicated S/R, once you’re acquainted with Regular expressions language :-))
For newby people, about regular expressions concept and syntax, begin with that article, in N++ Wiki :
http://docs.notepad-plus-plus.org/index.php/Regular_Expressions
In addition, you’ll find good documentation, about the Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v5.8 ), used by
Notepad++
, since its6.0
version, at the TWO addresses below :http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html
-
The FIRST link explains the syntax, of regular expressions, in the SEARCH part
-
The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part
You may, also, look for valuable informations, on the sites, below :
http://www.regular-expressions.info
http://perldoc.perl.org/perlre.html
Be aware that, as any documentation, it may contain some errors ! Anyway, if you detected one, that’s good news : you’re improving ;-))
-