Community
    • Login

    Mass replace inside file at once

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 1.5k 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.
    • Andy LightA
      Andy Light
      last edited by

      Hi. Is any way to replace multiple values inside one file at once?
      For example I want to replace"green" with “red” and “blue” with “black”. To do this, I must:

      1. Open Replace and enter in Find what word “green” and in Replace with word “red”. Then press Replace All.
      2. Then open Replace and enter in Find what word “blue” and in Replace with word “black”. Then press Replace All.

      Maybe there is some way to replace “green” with “red” and “blue” with “black” at once?

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Andy Light
        last edited by

        Yes, use a Regular Expression Search mode replacement to search for (green)|(blue) and replace with (?1red)(?2black).

        I think you’ll be able to see the pattern in that to extend it to other colors/searches.

        Andy LightA 1 Reply Last reply Reply Quote 4
        • Andy LightA
          Andy Light @Alan Kilborn
          last edited by

          @Alan-Kilborn thank you!

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Andy Light
            last edited by

            @Andy-Light

            Maybe it is also worth pointing out, if you need to do this same replacement often, you can record multiple replacement operations into a “macro”, give the macro a descriptive name, and then just run the macro when you need to. This saves the step of remembering the syntax I provided earlier.

            In summary:

            • begin macro recording
            • run as many individual replacement operations as you need to (two in the above case, your steps #1 and #2)
            • stop the macro recording
            • save the macro, give it a name
            • when you need to run it, find the name you gave it on the Macro menu and choose it

            All of the things you need are on the Macro menu (and also in the toolbar).

            The only downside: Say you are doing 10 individual replacements. You have to get them all correct on the first try while recording the macro, with no other intervening operations (as they would also be recorded into the macro). Not too difficult, but it must be kept in mind.

            1 Reply Last reply Reply Quote 1
            • PeterJonesP
              PeterJones
              last edited by PeterJones

              Say you are doing 10 individual replacements. You have to get them all correct on the first try

              “on the first try” is not likely, for me. :-) Personally, especially if they all used the same options, I would “do my best” on getting one or two recorded, then save and reload Notepad++, open shortcuts.xml, and copy/paste and manually edit the recording to get the others, save the file and reload Notepad++ again. Or record them as 10 separate macros, save and reload, then merge them manually in shortcuts.xml, save and reload Notepad++.

              Docs:

              • Macros overview: https://npp-user-manual.org/docs/macros/
              • <macros> section of shortcuts.xml: https://npp-user-manual.org/docs/config-files/#macros
              • Search-specific macro syntax: https://npp-user-manual.org/docs/searching/#searching-actions-when-recorded-as-macros
              Alan KilbornA 1 Reply Last reply Reply Quote 3
              • Alan KilbornA
                Alan Kilborn @PeterJones
                last edited by

                @PeterJones said in Mass replace inside file at once:

                merge them manually in shortcuts.xml

                For you, yes, but for a casual Notepad++ user, maybe not.
                I was just pointing out that a bit of serious concentration when recording macros will go a long way in helping out. :-)

                1 Reply Last reply Reply Quote 3
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors