views:

383

answers:

2

I'm looking for an open-source text editor which allows cross-line regular expression search and replace.

Thus, for example replacing \n with \n-------------------\n , and so introduce a dashed line between lines.

Or I could search for 08\nERROR and find

INFO 9329 21 June 2008
ERROR 3832 21 June 2008

UltraEdit has this feature, but that is a commercial product. I checked Notepad++, CrimsonEdit, etc., and did not find the cross-line search-and-replace.

+2  A: 

Vim knows how to do this.

for instance, if you have:

if (a) {
    x++;
} else {
    x--;
}

then searching with /;\n.*else will find this:

       ;
} else

and doing this replace: :s/;\n\(.*else\)/;\r//----\r\1/ will do:

if (a) {
    x++;
----
} else {
    x--;
}

(Note that I searched for the newline with \n but had to use \r in the replacement field)

Naturally, this will also work with your examples:

search for 08\nERROR and find:

                    08
ERROR
Nathan Fellman
Thanks, learning vim is useful. I tried this successfully. I have to admit I prefer GUI editors -- non-1337 though that is.
Joshua Fox
This works on gvim as well. That is vim with a gui
Nathan Fellman
A: 

At the time of writing, Notepad++ did not support this -- but the latest version now does!

Joshua Fox