Wednesday, January 13, 2010

Remove Visual Studio Regions with Find and Replace

Recently Uncle Bob was talking on twitter about regions. He says "Purge All Regions" - Well today's snippet is going to do just that.

The inspiration for this originated with Kyle Bailey's post from a few years ago. I had taken it, modified it, and today I share it with you; it can be used as a macro as Kyle created it, or you can use it right in Visual Studio’s Find and Replace.

Every developer knows how to use Find and Find/Replace, however I have only found a few that know that you can use regular expressions. The regular expressions that Visual Studio supports in the Find Dialog is a slimed down version and is specific to Visual Studio.

image

The following will work in both C# and VB, in the Find Options simply select “Use Regular Expressions” and replace with nothing. Change the Look in option to specify the scope of your search and you can make the change solution wide or just your current file.



^.*\#(end)*(:Wh)*region.*\n


Simple, quick and effective!

Wednesday, January 6, 2010

Locate File in Solution Explorer – Visual Studio Macro

Today's Macro is very basic, but I use it almost daily.

I use a customized IDE and one of the performance tweaks I have performed is to Turn Off the Track Active Items (Tools --> Options --> Projects and Solutions).

This feature, when enabled, syncs the selected item in your solution explorer to the file being viewed.

There are times that I have traced down into a file and then needed to locate it in the Solution Explorer; This Macro will assist you finding the current file while leaving the feature turned off.

(Other add-ins like ReSharper offer a similar feature "Locate in Solution Explorer")

About the Macro: The First Command toggles on the feature, the second toggles it back off - this allows Visual Studio to find the item in the solution explorer.

Then the third line simply causes the solution explorer to be displayed, this works if the solution explorer window is hidden or closed.

Bind it to a shortcut key and you are all set - mine is bound to (ALT+L, ALT+L)


Public Sub LocateFileInSolutionExplorer()
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
DTE.ExecuteCommand("View.SolutionExplorer")
End Sub