Visual Studio 2005 Tips #3: Using Surround with …

Another nice feature that will save on time and re-indenting your code is the Surrounds with snippets.  It works the same way as Code Snippets but the difference is that you highlight a section of code that you want to surround your code with.

This example I am going to surround a section of my code with a try catch.  The keyboard short cut is Ctrl + K and the S.

A popup combo box will appear asking you what type.  You can selec the you want to surround with.  Since I am going to use a try catch, I can hit the “T” key and then hit enter.

My code is now surrounded by a try/catch with the Exception object available for me to assign a variable to.

Visual Studio 2005 Tip#2:Writing your own Code Snippets

Now that you’ve seen the power of using Code Snippets, the only thing cooler is creating your very own code snippets!

The best tool that I’ve seen to help you create your own is one from Microsoft. It’s actually an open source project that if want to contribute to, you can.

You can download it from the MSDN website.