85

If the free source code editor Notepad++ has the feature "Find in files...", that is without the files being opened in the editor, does it also have the feature "Replace in files..."?

Notepad++ is based on the editing component Scintilla - for which at SourceForge there is a response to a request for this feature: "No need for this to be included in SciTE as you can add this command to the Tools menu using the Parameters dialog." So is it possible to do multi-line replace in files in Notepad++?

hichris123
  • 10,145
  • 15
  • 56
  • 70
Rob Kam
  • 10,063
  • 14
  • 55
  • 65

4 Answers4

87

It's easy to do multiline replace in Notepad++. You have to use \n to represent the newline in your string, and it works for both search and replace strings. You have to make sure to select "Extended" search mode in the bottom left corner of the search window.

I found a good article describing the features here: http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html

Alex
  • 9,250
  • 11
  • 70
  • 81
  • This is in a file already open. The question is how to do it in files without opening them in the editor. e.g. Replace all occurrences of foo with bar in files *.c in folder bas. – Rob Kam Nov 02 '10 at 07:46
  • 6
    You can do it for unopened files as well. It's the "Search->Find in Files" options in the menu or use the keyboard shortcut Ctrl-Shift-F – Alex Nov 05 '10 at 14:49
  • This is the answer, this should have been marked as the answer +1 – James Campbell Jul 27 '11 at 20:43
  • 3
    It's way easier using ToolBucket plugin for Notepad++ to multiline edit. Check my answer to more info. – Artur Haddad Aug 31 '15 at 16:16
  • 1
    It does require you though to make sure that the text contains none of those extended symbols or escape them beforehand. – makrom Jun 30 '20 at 16:44
83

Actually it's way easier to use ToolBucket plugin for Notepad++ to multiline replace.

To activate it just go to N++ menu:

Plugins > Plugin Manager > Show Plugin Manager > Check ToolBucket > Install.

Restart N++ and press ALT + SHIFT + F to multiline edit.

Artur Haddad
  • 1,429
  • 2
  • 16
  • 33
  • 1
    Worked perfectly, and I didnt need to install another editor! I was surprised that neither VS or emacs does this in an easy way. – sandos Jan 29 '16 at 09:11
  • 5
    The question is about replacing in [multiple] files. – Markus von Broady Aug 11 '16 at 13:58
  • 2
    @MarkusvonBroady you can find and replace in multiple files with this method – Artur Haddad Oct 03 '16 at 01:10
  • 1
    @ArturHaddad Yes, if you first open all of them, which can be problematic for a lot of files, but technically you're right. Aside from the need to open possibly a lot of files, you also may need a tool to automatically discover and open files in subfolders. – Markus von Broady Oct 03 '16 at 10:04
  • 1
    It works for English but didn't work for Japanese. So sad. – Moses Jun 29 '17 at 08:01
  • 3
    Note that as of 2018, the plugin manager is no longer included in notepad++, you'll have to manually install plugins or re-install the plugin manager yourself. – James Wong Aug 23 '18 at 10:00
13

The workaround is

  1. search and replace \r\n to thisismynewlineword

(this will remove all the new lines and there should be whole one line)

  1. now perform your replacements

  2. search and replace thisismynewlineword to \r\n

(to undo the step 1)

HTML Tiger
  • 139
  • 1
  • 2
  • While not an elegant solution, I had to use exactly this approach when doing a large, multiline search and replace within a Windows text editor. – siliconpi May 16 '12 at 16:08
  • If your replacement text doesn't contain escaped characters which are parsed by extended method (`\n`, `\r`, `\t` etc.) then you can make it easier by simply replacing `\r\n` with `\\r\\n` with no need to change anything back. – Markus von Broady Aug 11 '16 at 14:32
3

Notepad++ is still up and going so also you can install plugin ToolBucket from menu Plugins -> Plugin Manager. It doesn't improve native Notepad++'s Search and Replace dialog but uses its own with shortcut keys Alt+Shift+F

enter image description here

kolyaseg
  • 535
  • 5
  • 13