Mass replace inside file at once



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



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



  • @Alan-Kilborn thank you!



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



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



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


Log in to reply