30

Is there a way to find a paragraph?

For instance I want to search for this code:

<?php
    $radio_buttons++;
  }
?>

But when I try to copy that into the search box it only copies the first line, <?php.

It seems like there is definitely a way to do this, but I just can't find it. Maybe it is an addon?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sackling
  • 1,780
  • 5
  • 37
  • 71
  • I'm on a Mac right now so can't check, but I seem to recall that Notepad++ allows you to specify regular expression in the search field? – Matti Lyra Mar 30 '11 at 16:26
  • Yes it does but I still can't paste in more then a single line – Sackling Mar 30 '11 at 16:27
  • 1
    Refer to this http://stackoverflow.com/questions/405002/missing-desired-features-in-notepad. Looks like Notepad++ doesn't support multi-line search yet. There might a plugin for it but none that I've heard of. – Sahat Yalkabov Mar 30 '11 at 16:28

11 Answers11

59

I wrote a multiline search and replace add on for Notepad++, check it out here: http://www.phdesign.com.au/programming/toolbucket-multi-line-search-plugin-for-notepad/

ToolBucket Screenshot
(source: phdesign.com.au)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
phdesign
  • 2,019
  • 21
  • 18
  • 1
    This is great stuff. Thank you.. It was still a problem many months later and this works perfectly. If I did have just oneee tiny nitpick it is that using ctral + A to select all, which I do to erase a previous search does not seem to work. – Sackling Mar 07 '12 at 14:58
  • 1
    Thank you for developing that very useful tools. I've installed them to my desktop and portable versions of Notepad++. I'll recommend them to my colleagues. – Francisco Alvarado Mar 27 '12 at 21:45
  • +1 and thank you! I like that you made the find and replace similar to dreamweaver's GUI. The only thing missing is the option to save regexes. – t.mikael.d May 06 '12 at 10:03
  • Thank you Paul for the useful tool. @t.mikael.d the current version of the plugin already saves all previously used regexes, you can use these regexes by clicking the very small button with the calendar icon between the Find/Replace text boxes and the buttons on the right. – MohamedEzz Oct 18 '12 at 07:05
  • 2
    The plugin does not work with me with Notepad++ 5.x.x. But it works like charm with 6.x.x – MohamedEzz Oct 18 '12 at 07:13
  • 3
    Thank you for this wonderful plug-in, I work with lots of documents that require a multi-line search and replace feature. It's so nice that you have provided this great tool for the community. Thank you!! – klewis Feb 05 '13 at 22:30
  • There is one deal-breaker for me with this plugin: no option to replace in all open documents (like the default search has) – Sony packman Mar 24 '13 at 14:08
  • Great plugin Paul.. Is there also an option to replace text in files without opening them? i.e. giving it the directory to replace the text in it? Thanks – Mike Sep 13 '13 at 13:27
  • @Mike no there is now. Good idea bit its not possible with the windows file system POE of windows 10 – NightSkyCode Jun 05 '15 at 14:28
  • @phdesign I just tried to install this plugin, sadly it doesn't seem to be compatible with that latest version of Notepad++, there isn't a 64bit version available is there? – AidanO Jun 14 '17 at 08:24
  • There is support for 64-bit now (since June 2017). – hfontanez May 16 '19 at 21:42
23

As Xenovoyance suggests, it is possible with CTRL+R (also found in menu option TextFX > TextFX Quick > Find/Replace):

Just select your text to find, then invoke that option... Multi line find/replace

UPDATE: User Żabojad made me realise that in the latest releases of Notepad++, the "TextFX" plugin is not installed by default, so first you'll have to do one of two things:

  1. The easiest one: Go to menu option Plugins > Plugin Manager > Show Plugin Manager, scroll the available plugin list to "TextFX Characters" and install it. Install from Plugin Manager

  2. The above way should work, but otherwise you'll have go to this page : http://sourceforge.net/projects/npp-plugins/files/TextFX/TextFX%20v0.26/ and download file TextFX.v0.26.unicode.bin.zip Download TextFX Characters then extract its contents (don't just copy zip file) to the \plugins subfolder of the Notepad++ Install Folder Copy dll to Notepad++ plugins folder

After restarting Notepad++ you'll see the menu entry TextFX.

Community
  • 1
  • 1
Francisco Alvarado
  • 2,815
  • 2
  • 26
  • 51
  • 3
    Unfortunately this plugin doesn't seem to support editing multiple open documents either. – Sony packman Mar 24 '13 at 14:12
  • Ctrl+R didn't work for me until I went into Settings > Shortcut Mapper, and clicked on the "Reload from disk" line and clicked Clear to remove the conflicting Ctrl+R shortcut. – gamingexpert13 Jul 11 '19 at 17:43
9

Since Notepad++ 6.0 the regular expression search for multiple lines works.

The search for your code would be something like

<?php.*\r\n.*$radio_buttons++;.*\r\n.*}.*\r\n.*?>

.* is just wildcard for any number of characters (except line breaks). You can also toggle a checkbox in the Notepad++ dialog (called . matches newline) to include line breaks.

For a detailed description see the top answer of this question:

Find CRLF in Notepad++

Community
  • 1
  • 1
coeing
  • 913
  • 1
  • 11
  • 9
7

Cntrl+C the above text you want to find and Cntrl+V it into a new blank document in Notepad++, then Select it again and hit Cntrl+F . You will see your text into the "find" field with tabbed spaces as the line breaks. No need for plugins.

Leb_Broth
  • 1,081
  • 1
  • 15
  • 32
  • Confirmed in Notepad++ 6.6.9. You can check the actual search string in the `` sections within `` in Notepad++'s "config.xml" file. – AdrianHHH Dec 23 '14 at 08:39
4

To my knowledge Notepad++ doesn't support multi-line regular expressions, so you'll have to do this by replacing every line break with the representative line break characters for your operating system (most likely \r\n). See Find CRLF in Notepad++ for details.

Community
  • 1
  • 1
Ian Pugsley
  • 1,062
  • 8
  • 20
  • The problem is if you paste the paragraph into Search box, all you get is ' – Sahat Yalkabov Mar 30 '11 at 16:30
  • Not really - you can use the extended search to replace all `\r\n`s with some unused character (tilde, pipe, etc.), then use the non-extended search to replace that character with `\r\n` again (with non-extended `\r\n` will not create new lines). Voila - the search string. Also, you can make a macro out of this fairly easily. – Ian Pugsley Mar 30 '11 at 17:13
3

Multiple lines can be passed to search and replace fields only when lines endings are set to Unix form. This can be done via Edit>EOL Conversion>Unix

Then you can manually copy multiple line paragraph to search field.

After that, just convert line endings back to Windows via Edit>EOL Conversion>Windows

Jan Musil
  • 508
  • 5
  • 15
3

I found the following thread on a related subject: Multiline Regular Expression search and replace!

Recommend that you try out CTRL + R!

Community
  • 1
  • 1
Xenovoyance
  • 330
  • 1
  • 2
  • 10
  • trying CTRL + R it does not seem to be working. Not sure which options to have selected yet. – Sackling Mar 30 '11 at 16:36
  • I just tried it on my machine here (notepad++ 5.8.6) and I could search for a multi-line blog of text. Perhaps running an older version? – Xenovoyance Mar 30 '11 at 16:39
  • yep I was on 5.8.6 and actually just updated to .7 it seems to work sometimes** like in a paragraph on a txt file but doesnt seem to like when searching for a block of code with white space between it. Maybe it is an option I am missing. – Sackling Mar 30 '11 at 17:27
  • Just realized "selection" was ticked off it seems to work now! Thanks! – Sackling Mar 30 '11 at 17:30
  • It's really through the plugins Notepad++ really start to shine. Glad to help! – Xenovoyance Mar 30 '11 at 19:38
2

For a Notepad++ v5.8.7+ there is no TextFX plugin for Unicode installed by default, so in order to use CTRL+R you need to install TextFX Characters plugin with Plugin Manager.

mykola.rykov
  • 522
  • 6
  • 13
1

There is a workaround:
Change the search mode to Extended and replace "return-newline"s with \r\n
eg <?php\r\n $radio_buttons++;\r\n }\r\n?>
Problem is you need to know the white space (not shown above).

Maybe a regex could work?

Michael Blake
  • 2,068
  • 2
  • 18
  • 31
0

Check out the TextFX menu option. That looks like it supports multiple line searching.

Michael Blake
  • 2,068
  • 2
  • 18
  • 31
0

in the latest notepad++, simply select all the multiline text you want to search and press ctrl+f, it will automatically put the text to be searched in the search field formatted for multiline search.