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

廉价感情. 提交于 2021-02-18 07:06:15

问题


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


回答1:


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




回答2:


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.




回答3:


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

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




回答4:


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!



来源:https://stackoverflow.com/questions/13083630/notepad-replace-two-lines-with-other-10-lines-in-open-documents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!