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>" />

    All help is appreciated… Thanks!

  • @liuruiqi1993

    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.


    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 to Regular Expression

    Start macro recording.
    Press the Replace All button.
    Stop macro recording.
    Save macro, assign keycombo.

  • @Scott-Sumner


    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)]

  • @liuruiqi1993

    I can tell that you haven’t tried it.
    HINT: Try it…or see the Clue below…

    Clue : 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="" />

  • 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="&lt;bold&gt;$0&lt;/bold&gt;" />
                <Action type="3" message="1702" wParam="0" lParam="640" sParam="" />
                <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />

    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="&lt;bold&gt;$0&lt;/bold&gt;" />

    I think that the later form should be the right one ! That is to say that the special characters < and >, should be coded as &lt; and &gt;, 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> !



  • @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 :

    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 :

    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 its 6.0 version, at the TWO addresses below :

    • 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 :

    Be aware that, as any documentation, it may contain some errors ! Anyway, if you detected one, that’s good news : you’re improving ;-))