Here are my top 11 tips and tricks for getting things done faster with the Visual Studio 2005 IDE (without using third-party add-ins or upgrading hardware… that’s another article). Yes, some of these tips and tricks may fall into the "obvious" category, but I think they are worth repeating. I continue to see too many .NET developers not taking advantage of even the basic time-saving techniques.

I work mostly with C# so some of these tips may not apply to, or work differently with other Visual Studio languages such as Visual Basic.NET.

(1) Express Yourself with Regular Expressions

Regular Expressions is a powerful and portable text search/replace/transformation language. Learning basic Regular Expressions will immediately make you a more productive developer/power user. Regular Expressions is supported in Visual Studio’s various Search/Replace dialogs. Any Regular Expressions skill you learn will also be useful in numerous other applications and settings: other text editors, unix shell/egrep, PowerShell, input validation, and Google search (heh, just kidding on that last item).

You can also use Regular Expressions with macros and automation via the Regex class.

Here’s an example of how you can save time with Regular Expressions in Visual Studio. Say, you just wrote and tested a SQL in a Query Tool and you want to turn it into a string variable in your C# class? Here’s how:

First, paste the SQL text into the editor. Make sure to remove any unwanted indentation on the left side of the text (SHIFT-Tab):

Then hit CTRL+H to bring up the Find and Replace Dialog and fill it out like this:

Note: For VB.NET, in the “Find and Replace Dialog Window”, change the value in “Replace With” box: from {[ + “\1″ ]}… to {[ & “\1″ _ ]}. Thanks to berkx for this info.

Explanation? Basically, the "Find what" expression above matches the content of each line and give it a numbered "tag". The "Replace with" expression then replaces each line with the first tagged value (\1), wrapped around in + " ". Click the fly-out (triangle) button next to each box to display a cheat-sheet of frequently used expressions. Oh, and don’t worry about the "+" string concatenations in the example, the compiler knows to optimize that syntax.

Once you’ve created a few Search/Replace expressions like the above, create macros out of them and assign to shortcuts.

Here are some of the Regex transformations I use most often when writing code:

Surrounds each line with (example above).

Transform a list of values separated by newlines into a coma-delimited list (used in array initializers or SQL where clause).

(4) Use Code Snippets

Save time typing repetitive code by using Code Snippets. There are two types of Snippets in Visual Studio 2005: Expansion and SurroundsWith. To use Expansion Snippets, type the Snippet shortcut (not to be confused with keyboard shortcuts), and press Tab twice.

For example, the "for" Snippet is an Expansion Snippet. To use it, type "for"…

Then press Tab, Tab:

I find SurroundsWith Snippets more useful though. An example SurroundsWith Snippet is "#region". First, select a block of code:

Then, type CTRL+K, CTRL+S and "#re":

Then hit Enter:

Here are my favorite Snippets:

#region: Regions is a great way to organize your code.

using: If you create an IDisposable object, you should use the "using" pattern. In addition to the basic "using" Snippet, I also created several variations for TransactionScope, and IDataReader.

(5) State Your Preferences

Find yourself constantly switching to the Design view every time you create/open an ASPX page? Cannot locate your current file in the Solution Explorer? Easy… just change the right settings and never think about it again.

(6) "Attach to Process" to Start Debugging ASP.NET

Most ASP.NET developers use the standard F5 (Debug/Start Debugging) to start debugging from Visual Studio. However, there is a much faster way to start debugging if you already have an instance of your web application running. Just attach to it instead:

Choose Debug/Attach to Process.

Select the "aspnet_wp.exe" process and choose Attach.

Or, for keyboarders:

ALT+D, P, "as", Enter.

Debugging this way is faster because you skip the often-lengthy compilation step, and you don’t have to navigate from the start page to the actual page that you want to debug.

(7) Stop Conditionally (Conditional Breakpoints)

How often have you found yourself repeatedly stepping through a loop while debugging, waiting to get to a specific loop value (because the bug only occurs with that specific value)? With Conditional Breakpoints, you don’t have to do that. Just set a Breakpoint Condition.

Set the Breakpoint. Right click on the Breakpoint indicator (red circle), and choose Condition:

Set the condition (any valid C# expression):

Another debugging productivity trick I use is to override ToString() to return a useful summary of your objects. The Debugger uses the value returned by ToString in various Debug windows such as Watch Window. You can also use the DebuggerDisplay attribute.

(8) Employ Task List Tokens

Use Task List tokens such as TODO and HACK to quickly mark incomplete code or code that requires further attention. This allows you to keep flowing and skip over the details, but at the same time ensures that you will not forget to go back and finish up.

A shortcoming with Visual Studio 2005’s Task List is that it only shows the items in the current file. You can get around this by using the Find in Files feature and search for "// TODO".

(9) Go Directly to Any File with the Find Combo Box

This is the Find dropdown that is on the Standard Toolbar, not the Find dialog. Use the shortcut CTRL+D to activate the Find dropdown in normal mode. Use CTRL+/ to activate the Find dropdown in command mode (with ">" prepended… this doesn’t work sometimes for me).

To quickly go to a file, type CTRL+D, >open <start of file name>. Intellisense works here just like in the Command Window. "of" (short for "open file") can be used instead of open. Compare this with opening Solution Explorer, expand the correct folder/project, and visually hunt for the file you need.

With the Find Combo, you can also execute commands, macros, find text, etc. More info: