views:

112

answers:

5

I need to do a find and replace, where I need to replace 2 lines at time. Does anyone know how to do this in the VS2008 IDE?

To clarify, i want to replace 2 lines with 1 line.

Many thanks

+1  A: 

The Find and Replace dialog allows the use of regular expressions. Try tossing a \n in the find string for the newline with the regular expressions option turned on.

David
Yeah, gave that a go before posting the question. Not that easy i'm afraid.
Iain Hoult
What problem are you running into? I just tested a simple scenario here and it's working. How complex is the find/replace you're doing?
David
Also, you can use `:b*` to match empty characters at the start of line. So something like `first line:b*\n:b*second line` should work. Beware some special characters like parenthesis though, you must escape them: `\\(` in your search string.
František Žiačik
Thanks František, that works brilliantly
Iain Hoult
A: 

You can activate the 'Use regular expressions' in the find dialog, and use \n to match a newline. In your case, type FirstLine\n:Zs*SecondLine.

:Zs* skips leading blanks on line 2.

For example ,\n:Zs*c matches a comma, newline, any number of blanks, a 'c'.

Mau
instead of :Zs you can use :b which matches tabs, too
tanascius
A: 

Thanks to František Žiačik for the answer to this one.

To perform a find/replace, replacing multiple lines, you need to switch on regular expressions and use a line break (\n) between your lines, also using (:b*) at the start of each line to handle any tabs or spaces tabs.

So to find:

line one
line two

you would search for ":b*line one\n:b*line two" (without the quotes)

Iain Hoult
A: 

Try Multiline Search and Replace macro for Visual Studio.

Peter Macej
A: 

You can replace multiple lines with PilotEdit Lite. It is free. http://www.pilotedit.com

Dracoder