6

I want to replace two lines with other lines in Notepad++.

The main problem is that I am not able to copy all the lines which should be replaced. Only the first line is inserted in the "Replace with:" input field if I paste all lines in the field. It seems that the line break is not correctly copied.

Selecting the lines (with the line break) which should be inserted in the "Find what:" field is quite easy because I can select them in the document and simply hit "CTRL + H".

What to do? Please no solutions how it could work with command line tools.

Regards

3
  • 1
    Don't use 'Replace with' then. Just use find and ctrl+v to paste.
    – Codeguy007
    Commented Oct 26, 2012 at 8:58
  • @Codeguy007 ??? And how should I replace lines with "Find"?
    – sk2212
    Commented Oct 26, 2012 at 9:00
  • @Codeguy007 That should maybe work for one document (it did not anyway) but I have 200 opened documents and I want to replace the two lines in all opened documents. Furthermore if I hit "Find" I could NOT replace the found lines with "CTRL + V". Did you try it?
    – sk2212
    Commented Oct 26, 2012 at 9:09

4 Answers 4

8

Albeit a bit late for an answer, I think it's OK.

You can not search for a multi line string in Notepad++ using the normal search mode.You should use the extended search mode instead.

You just have to escape the new lines.What's best, you can use Notepad++ to prepare the escaped text to be searched and replaced.

I assume you are using windows text files meaning the new line is represented with \r\n

To achieve what you want:

1.

  • Create a new document and paste your multiline text to be replaced
  • Do a replace on it using the extended search mode. Find what: \r\n Replace With:\\r\\n
  • The result will be your "Find what" string.

2.

  • Create a new document and paste your multiline replacement text
  • Do a replace on it using the extended search mode. Find what: \r\n Replace With:\\r\\n
  • The result will be your "Replace with" string.

3.

Now that you have your escaped data, do a Replace on all the open documents using the extended search mode AND the results from the previous steps.

Hope this helps.

7

None of these suggestions are acceptable! TextFX's Ctrl+R replace plugin falls way short.

What EVERYONE wants, everyone that wants to perform a replacement of multiline blocks of text with another multiline block of text, is this...

2 large text boxes:

Find This:

This is line one

This is LIKE two

This is line TREE

Replace with This:

This is line 1

This is line 2

This is line 3

A checkbox for "All Open Documents"

And/Or...

Option for "Find-Replace in all Files of Type"

Then a GO button............

How hard could that be to create in Notepad++? It was done way back in 1998, a freeware utility called Search-Replace 98.

UPDATE:

The plugin suggested by numediaweb DOES EXACTLY what I needed! Hats off to numediaweb for the tip and standing applause for paul at phdesign!

ToolBucket multi-line search plugin for Notepad++

http://www.phdesign.com.au/programming/toolbucket-multi-line-search-plugin-for-notepad/

ToolBucket contains the following features:

Multi-line search and replace dialog.
Change indentation dialog.
Generate GUID
Generate Lorem Ipsum
Compute MD5 Hash
Compute SHA1 Hash
Base 64 encode
Base 64 decode

Download

The latest version is available here: https://github.com/phdesign/NppToolBucket/downloads

1
  • This Plugin is really nice! Works perfect!
    – sk2212
    Commented Jul 7, 2014 at 12:03
2

For regular expressions you can use Ctrl-R, aka TextFX -> TextFX Quick -> Find/Replace.

If not check this plugin, it does what you want!

0

Based on the response of Nikanos Polykarpou below is my...

Notepad++ - Replace by a multiple lines string

Select the string to replace (can have multiple lines).

Follow...

Ctrl+h -> Replace (tab) -> Enable "Extended (\n, \r, \t, \0, \x...)"

... in "Replace with:" enter a string to do the replace with "\r\n" (if Windows) instead of real line breaks as this example...

"model" "models/aztec100500/flo_grass.mdl"\r\n"framerate" "10"\r\n"angles" "0 30 0"\r\n"classname" "cycler_sprite"

... do the replace!

Not the answer you're looking for? Browse other questions tagged or ask your own question.