Iain Hoult
Iain Hoult

Reputation: 4005

How to replace multiple lines in Visual Studio 2008

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

Upvotes: 4

Views: 4718

Answers (3)

Peter Macej
Peter Macej

Reputation: 5577

Try Multiline Search and Replace macro for Visual Studio.

Upvotes: 3

Iain Hoult
Iain Hoult

Reputation: 4005

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 ":bline one\n:bline two" (without the quotes)

Upvotes: 6

Mau
Mau

Reputation: 14468

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'.

Upvotes: 0

Related Questions