Community
    • Login

    new lines in replace?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 3.8k 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.
    • kracovwolfK
      kracovwolf
      last edited by kracovwolf

      So, I need to replace text. In “Find what”, it handles new lines in between characters/text just fine. However, the “replace with” field doesn’t recognize new lines from pasting. It simply cuts off all content after the new line/linebreak.

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

        @kracovwolf

        Use Extended for the Search mode and then use \r\n in the Replace with text where you want the “new line/linebreak” to occur.

        1 Reply Last reply Reply Quote 1
        • guy038G
          guy038
          last edited by guy038

          Hello, @kracovwolf, @alan-kilborn and All,

          The solution, provided by @alan-kilborn which uses the Extended search mode is really valuable !

          In fact, except in very rare cases, the syntaxes of the replacement part : Line1\r\nLine 2\r\nLine3\r\nLine4\r\n... will preserved the syntax of each line !

          BTW, if you’re usually deal with UNIX files ( see on the right part of the status bar ), you’ll have to change the REPLACE part as below :

          Line1\nLine 2\nLine3\nLine4\n...


          For example, from this INPUT text :

          ab$cD^E\Fg-h()iIJ[]K:L
          
          • Open the Replace dialog ( Ctrl + H )

          • Unckeck all box options

          • SEARCH ab$cD^E\Fg-h()iIJ[]K:L

          • REPLACE ab$c\r\nD^E\F\r\ng-h()i\r\nJ[]K:L

          • Check the Wrap around option

          • Select the Extended ( \n, \r, \t, \0, \x... search mode

          • Click on the Replace All button

          => You get the expected OUTPUT text :

          ab$c
          D^E\F
          g-h()i
          J[]K:L
          

          In these others posts, below, I imagined a way to insert a multi-lines text, using the Regular expression search mode :

          https://community.notepad-plus-plus.org/post/97866

          https://community.notepad-plus-plus.org/post/97904

          However, now I see that the Extended search mode or, even better, the Normal mode could drastically simplify the method when applied to a single file !


          So, when you want to insert a multi-lines text, even in several locations, of the current file, just follow this method :

          • Let’s suppose that this INPUT text, below, is the text to be inserted :
          -------------
          Inserted
          Multi-lines
          Text 
          -------------
          
          • First, paste the text to be inserted in a new tab

          • Select this multi-lines text without its last line-break ( so the line-break after the series of dashes )

          • Open the Replace dialog ( Ctrl + H )

          => The multi-lines text should be copied in the Find what: zone

          • Now, let’s switch to this text, in an other tab, which is the main text :
          bla
          blah
          ¤
          bla
          blah
          <test>¤</test>
          blah
          bla
          Begin ¤
          blah
          bla
          blah
          ¤ end
          

          Note that I use the ¤ symbol as an insertion symbol !

          • Click on the ⮁ symbol, of the replace dialog, in order to swap the Find what and Replace with zones

          => The multi-lines text has moved into the Replace with : zone

          • Insert a single ¤ symbol in the Find what : zone

          • Unchek all the box options

          • Check the Wrap around option

          • Select the Normal search mode ( No need to choose the Extended mode )

          • Click on the Replace All button

          => The ¤ should have been replaced by the multi-lines text in four locations and you get the following OUTPUT text :

          bla
          blah
          -------------
          Inserted
          Multi-lines
          Text 
          -------------
          bla
          blah
          <test>-------------
          Inserted
          Multi-lines
          Text 
          -------------</test>
          blah
          bla
          Begin -------------
          Inserted
          Multi-lines
          Text 
          -------------
          blah
          bla
          blah
          -------------
          Inserted
          Multi-lines
          Text 
          ------------- end
          

          Best Regards,

          guy038

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