Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ replace two lines with other (10) lines in open documents

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

like image 468
sk2212 Avatar asked Oct 26 '12 08:10

sk2212


People also ask

How do you replace multiple lines in notepad?

Invoke the Replace dialog (via pressing ctrl+h) Select your desired text to be searched back in the editor tab window. Move back to the Replace window and tick the checkbox for In Selection. Specify what you are searching for and what you are replacing it with, and any other options…


3 Answers

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.

like image 188
Nikanos Polykarpou Avatar answered Oct 20 '22 00:10

Nikanos Polykarpou


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

like image 31
Not.Impressed Avatar answered Oct 19 '22 22:10

Not.Impressed


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

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

like image 35
numediaweb Avatar answered Oct 19 '22 22:10

numediaweb