Community
    • Login

    new lines in replace?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 28.9k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors