Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


Replace a block of text by an other

  • Hi,

    Notepad++ seems to answer to my requests.
    But... How can I replace a block of text with an other ? This block is composed of several lines of text, and the replacing block hasn't always the same size and the same number of lines.
    The Find and Replace command seems to work only ont he same line.
    Thank you in advance

    • Don HO
      Don HO

      Use the TextFX plugin (Ctrl-R) which comes with Notepad++.


  • CapnCrunch

    That's what I am here for as well…. to suggest and request a more flexible Find/Replace.  I used to use a program called "Search-Replace 98" and it had Amazing replacement functionality. As awesome as Notepad++ is (I can't get any work done with out it!), something more like Search-Replace would be great in Notepad++.  I could search for a (multi-line) block of text and replace it with another block of text.

    Not sure if this is possible, and maybe it sounds crazy but… is there a way to perform a search that looks (in pseudo) something like this …?

    original file contents:
      File1: Block of text with STUFF in it
      File2: Block of text with JUNK in it

    search for
      Block of text with ? in it

    replace with:
       Block of text with ALL MY GOOD  * in it

    resulting in:
      File1: Block of text with ALL MY GOOD STUFF in it
      File2: Block of text with ALL MY GOOD JUNK in it


  • cchris

    It is possible both by using TextFX's Quick Search/Replace, or using regular expressions in Notepad++, as \r, \n and \R are available.


    • CapnCrunch

      No, Don HO.
      No, CChris.

      Thanks for your replies but... that's Not like "Search Replace 98".

      The TextFX plugin does a replace of a block of text, this is true -- for the currently viewed document. However, unless I am missing something it appears to me that it does not perform that task across "All Open Documents" nor, "Find/Replace in Files".

      Search Replace 98 was an indispensable tool for this reason. As great a program as Notepad++ is I don't understand why a (GOOD) block text replacement function isn't a NATIVE ability of the application itself.


    Hello CapnCrunch,

    May be I didn't understand clearly what you need, but I think it's quite possible to get what you would like to, with Notepad++ :-)

    First of all, for a test, create, in a folder, two files Test1.txt and Test2.txt.

    • The first one contains 5 identical lines : Block of text with STUFF in it

    • The second one contains 5 identical lines : Block of text with JUNK in it

    Then, just follow the method, below :

    • Open the Find in Files dialog ( CTRL + SHIFT + F )

    • Type, in the Find what zone : (Block of text with )(.+?)( in it)

    • Type, in the Replace with zone : \1ALL MY GOOD \2\3

    • Type, in the Filtrers zone : Test*.txt

    • Type, in the Directory zone, the full path of the folder, containing the two files Test1.txt and Test2.txt, or search this folder by clicking on the ... button

    • Select the Regular expression search mode

    • Uncheck, if necessary, the . matches newline option

    • Click on the Replace in Files button

    • Click on the OK button of the Are you sure confirmation dialog

    Et voilà ! => The string ALL MY GOOD is added, after every string "Block of text with ", in all the lines of the two files Test1.txt and Test2.txt

    Best Regards,


    Last edit: THEVENOT Guy 2014-07-05
  • Loreia2

    Hi THEVENOT Guy,

    he wants to be able NOT to use regex (or extended mode) and to be able to replace multiline strings. In principle this is possible if edit box in search dialog is multiline edit box. But it would require redesigning the dialog, not to mention that this is a non standard behavior for search/replace dialog.



    If you select multiple lines and press Ctrl + F, then it works.
    But it is impossible to drag some lines in the field of replacement


    Hi CapCrunch, Loreia2 and Azjio,

    Oh, Loreia2, I see ! So, I suppose that CapnCrunch would like, for example, three zones in the Search/Replace dialog.

    • The first would contain some string, before the real match wanted, that should be matched

    • The second would contain the exact text or regex to match

    • The third would contain an other string, after the real match wanted, that should be matched too

    With that way, you avoid building regex with lookarounds, at the boundaries of the exact regex to match :-)

    However, as the 1st and 3rd zones may also contain regexes, spliting the totality of the search string in three parts is not very useful ?! You would better build a complete regex to paste in the Find what zone !

    Thanks, Azjio for your method that I didn't use, up to now. Of course, to do so implies a normal or an extended search only, as the multi-lines text, to paste, may contain some special regex characters !



    Last edit: THEVENOT Guy 2014-07-08
  • Loreia2

    Thanks AZJIO,

    I guess something similar should be converted to Notepad++ plugin. Essentially, it should just have two multiline boxes, and it should convert user input into "extended" search/replace operation in editor.



    Hi Azjio,

    Although, I did some timid tries to program , in Python, with Loreia2's help, I'm not very acquainted with modern structured languages : I'm an old guy and I was trained, rather with the old Microsoft Qbasic than with C++ !!

    So, I'd be very satisfied if I could program softwares like yours : TextReplace, RegExp ... :-) Certainly, you're quite able to do plugins for Notepad++. But, perhaps, you prefer to program independent softwares. It's quite your right !

    Let go back to our discussion : finally, I admit that your multi-lines text feature in, both, search and replace fields, is easier to understand for people, not comfortable with regex's syntax !

    With Notepad++, the only method to write EOL characters in the replacement field, in normal search mode, that I found out, is :

    • Close Notepad++

    • With an other editor ( Notepad, Wordpad,... ) open the config.xml file

    • Write your multi-lines text in the most recent Replace name tag, while replacing any EOL by the string


  • Save the config.xml file

  • Re-start N++ and open the Search/Replace dialog ( CTRL + H )

  • For example to replace the two lines text :


    by the two lines text :


    you should write, in the config.xml file, the most recent Replace name tag, below :

    <Replace name="123&#x000D;&#x000A;456&#x000D;&#x000A;" />

    And, the most recent Find name tag should, already, be written :

    <Find name="abc&#x000D;&#x000A;def&#x000D;&#x000A;" />

    Of course, this is a VERY UGLY way to proceed :-((

    It's much better to use the Extended search mode and insert the symbols \r\n, \n, or \r, in the replacement field, each time you want your text go to a next line.