Multiline Search and Replace in Visual Studio (2013-2005)
- 03 Mar 2014 17:57
It's been 8 years since I wrote a Multiline Search and Replace macro for Visual Studio. At that time, I only needed some multi-line replacements and I had no idea how popular the macro could be. A lot of comments and visits proved that this is really something MS should implement directly in VS. Now we have VS 2013 and multiline find and replace still isn't there. What's worse, support for macros was removed from VS 2012 and higher, but that's another topic. So neither my macro helps now.
So I converted the macro to Visual Studio package (extension) and now you can use it in Visual Studio 2005-2013. You can download it here.
This extension allows multiline search and replace in Visual Studio. It is a user-friendly GUI wrapper over standard VS "Find" and "Find in Files" dialog. You don't have to use the regex syntax, the extension takes care of it.
After installing, a new Multiline Find/Replace menu item is created under Edit - Find and Replace.
When you invoke the command, you can insert multiline text in both Find what and Replace with fields.
According to which find or replace button you press, the standard VS find/replace dialog appears. All required fields are correctly prepopulated. That means Find what and Replace with fields contain the regular expressions for newlines. Moreover, the Use Regular Expressions option is automatically selected.
Now you know it. You can search and replace as usual.
Predefined keyboard shortcut for the multiline search command is Ctrl + Alt + F. If you want to change it (for example because the shortcut is already used) you can do it in Tools - Options... menu. Navigate to Environment - Keyboard. Type "multiline" in Show commands containing field. You should see Edit.MultilineFindReplace command for which you can change the shortcut.
To add the command to your toolbar, right click on the toolbar and select Customize. Switch to Commands tab. Select Toolbar: Standard and press Add command. Select Edit category and Multiline Find/Replace command.
And now it's always at your hand.