Community
    • Login

    Macro command

    Scheduled Pinned Locked Moved General Discussion
    7 Posts 4 Posters 1.7k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Paunescu MariusP Offline
      Paunescu Marius
      last edited by

      Hello. I have a word of the form ”xxxxxx” and I want to change it to the word „xxxxxx”, what is the command for a macro in notepad++? I would like to have a command that can change all words of this type in all open documents. Plaese help me, thanks.

      PeterJonesP mkupperM 2 Replies Last reply Reply Quote 0
      • PeterJonesP Online
        PeterJones @Paunescu Marius
        last edited by PeterJones

        @Paunescu-Marius ,

        To do a search/replace, use Search > Replace (Ctrl+H). If you want to use wildcards (that is, if xxxxxx was meant to mean “any text” rather than “six literal x characters”), then you would use Regular Expression mode: so

        • Find What: "(.*)"
        • Replace With: „$1”
        • Search Mode: Regular Expression
        • Replace All

        If you were going to be doing that same replacement frequently, for days or weeks or months to come, then you could use the macro feature: Macro > Start Recording, do that replacement once so it gets recorded, Macro > Stop Recording then Save Current Recorded Macro and give it a name (and maybe a shortcut) – then the Macro menu (and the shortcut) would have your search/replace saved so you could use it from the menu (or a keyboard shortcut).

        I would like to have a command that can change all words of this type in all open documents.

        update: I didn’t notice this during my initial reply. For that, I would recommend not using the Macro, and just using the Replace dialog. And instead of hitting Replace All, you would use Replace All in All Open Documents.

        -—

        Useful References

        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        1 Reply Last reply Reply Quote 1
        • Alan KilbornA Offline
          Alan Kilborn
          last edited by

          In this case, since @Paunescu-Marius didn’t post with proper formatting, we are not sure if his starting point is “curly” double quotes, or “traditional” quotes.

          1 Reply Last reply Reply Quote 1
          • mkupperM Offline
            mkupper @Paunescu Marius
            last edited by

            One of the things that is not clear from @Paunescu-Marius’ post is if there are ever orphan quotes, two or more quoted words or phrases on a line, quoted things that span two or more lines, etc.

            It may be safer to use:
            ** Search: "(\u+)"
            Replace: „$1”

            It’s the same as what @PeterJones suggested but uses \u+ instead of .*. However, it will only match and fix single words enclosed in quotes such as "this" and will not match a series of two or more words separated by spaces, that contain punctuation, etc.

            Doing a search/replace on all open documents is always a deadly game and so it’s best to make a backup of the data before attempting clean it and as conservative as possible when constructing the search or match part of a regular expression.

            PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 1
            • PeterJonesP Online
              PeterJones @mkupper
              last edited by

              @mkupper ,

              Good point. And my ".*" is probably too greedy, so ".*?" would be better.

              But until @Paunescu-Marius gives more detail, making too many more guesses is probably pretty inefficient for us (and likely to still not hit the mark for the hidden details)

              1 Reply Last reply Reply Quote 1
              • Alan KilbornA Offline
                Alan Kilborn @mkupper
                last edited by

                @mkupper said:

                Search: “(\u+)”

                I’m not confident that \u is the “best” thing to use here…and also it fails miserably if Match case is inadvertently checkmarked…

                mkupperM 1 Reply Last reply Reply Quote 2
                • mkupperM Offline
                  mkupper @Alan Kilborn
                  last edited by

                  @Alan-Kilborn said in Macro command:

                  @mkupper said:

                  Search: “(\u+)”

                  I’m not confident that \u is the “best” thing to use here…and also it fails miserably if Match case is inadvertently checkmarked…

                  You are right. It should have been a search for (?i)"(\u+)" and I even have the (?i) part in my own notes about using \u. I had noticed that English is likely not the OP’s first language which is why I thought of \u as it also matches letters with diacritics.

                  1 Reply Last reply Reply Quote 2

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors