• Login
Community
  • Login

Macro command

Scheduled Pinned Locked Moved General Discussion
7 Posts 4 Posters 240 Views
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.
  • P
    Paunescu Marius
    last edited by Jan 25, 2025, 3:07 PM

    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.

    P M 2 Replies Last reply Jan 25, 2025, 5:42 PM Reply Quote 0
    • P
      PeterJones @Paunescu Marius
      last edited by PeterJones Jan 25, 2025, 5:50 PM Jan 25, 2025, 5:42 PM

      @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
      • A
        Alan Kilborn
        last edited by Jan 25, 2025, 6:10 PM

        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
        • M
          mkupper @Paunescu Marius
          last edited by Jan 26, 2025, 12:07 AM

          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.

          P A 2 Replies Last reply Jan 26, 2025, 12:18 AM Reply Quote 1
          • P
            PeterJones @mkupper
            last edited by Jan 26, 2025, 12:18 AM

            @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
            • A
              Alan Kilborn @mkupper
              last edited by Jan 26, 2025, 11:32 AM

              @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…

              M 1 Reply Last reply Jan 28, 2025, 9:24 PM Reply Quote 2
              • M
                mkupper @Alan Kilborn
                last edited by Jan 28, 2025, 9:24 PM

                @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
                6 out of 7
                • First post
                  6/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors