Replace several lines

543 Views Asked by At

In Notepad++, I would like to (find-in-files and) replace several lines, but I fail to paste several lines into the "Replace what:" text-box.

I select the lines in an opened file, press Ctrl+Shift+F, and I get the lines copied into the "Find what:" text-box. "Extended" is pre-selected.

The problem is, when I try to copy the lines from the "Find what:" text-box to the "Replace with:" text-box, only the first line is copied. Had the lines appeared with \r\n it would have solved the problem, but they don't. (I did get once the lines to appear in "Find what:" with the \r\n, but I don't know what caused it.)

2

There are 2 best solutions below

0
On BEST ANSWER

A cumbersome workaround:

  • open a file with the multiple-lines you want to copy (but can't) into the find/replace box.
  • replace (using "Extended") all \r\n into \\r\\n.
  • you can now copy the multiple-lines as one line (with the new \r\n as text) to the search-box.
1
On

The Find what and Replace fields take a single line each. Those lines can match or generate, respectively, multiple lines by inserting the four characters \r\n where line breaks are needed; provided the Extended or Regular expression are selected.

To generate four lines of text the Replace field could be set to contain these 31 characters One\r\nTwo\r\nThree\r\nFour\r\n


Notepad has three search modes to control how the characters within the Find what and Replace fields are interpreted. See the Searching ... Normal search part of the Notepad++ help pages for more details.

Normal means is handled literally. That means a Find what string such as s\t looks for the three letters s, \ and t in that order.

Extended means that \ characters are used to indicate special characters such as newline and tab characters, etc. That means a Find what string such as s\t looks for the two letters s and TAB in that order. To look for the three letters s, \ and t in that order needs the Find what string to be s\\t.

Regular Expression means that several other characters are interpreted, not as themselves but, specially as parts of a regular expression.