Code Snippets in VS.NET 2005

One of the most enjoyable new features in Visual Studio .NET 2005 is Code Snippets. This animated GIF illustrates how it works:

This is a companion discussion topic for the original blog entry at:

It’s nice to see Microsoft adopting features other IDEs have had for years.

Borland’s Delphi has had it for years via the CodeRush add-in. It will be standard in Delphi 2006 (Borland Developer Studio). Borland calls it Live Templates.

I am sure when Microsoft finally delivers a live two-way modeling tool and object persistent framework, we’ll hear praise of how ingenious they are. In the meantime, I can continuing using Delphi and get those features /now/.

has had it for years via the CodeRush add-in

Well, yeah, but everyone has had everything for years via “add-ins”. It just depends how obscure you want to get.

However, there’s a huge practical difference between add-in and “included in the box”.

I’m not saying it’s better than the third party solutions, mind you, but… it’s in the box. It’ll get used by several orders of magnitude more people.

So finally, it’s able to do the same I’m used to Eclipse for years (and was wondering, why it doesn’t exist in Visual Studio .NET 2003).

It’s nice but I never learned the shortcuts for complete blocks of code (like ‘svm’ for static void main).

Also useful (and I assume it exist in VS .NET 2005 as well) is the ability to comment out selected lines with pressing CTRL-SHIFT-7) and uncommenting it again with pressing the same combination.

Best regards, Lothar

Yeah, that’s…

CTRL+K, CTRL+C (comment)
CTRL+K, CTRL+U (uncomment)

I first encountered snippets in Homesite. I’m glad to see that VS.NET has joined the ranks of editors I would consider using.

I don’t think I’ve ever thought to share my snippets with anyone, though. To me, code snippets are very personal. They’re tuned to what my brain thinks is a block of recurring code. The shortcuts are easy to remember because I thunk 'em up myself.

How did you make that animated GIF?

A better place to put your own snippets is in the folder provided in your My Documents\Visual Studio 2005\Code Snippets folder. It will save you time when you want to export them. Although, if you edit the ones provided by VS, you’d have to move them too, if you want to keep them.

I really like the surround with for XML files. I’m always forgetting elements and the surround with makes it way easier.

btw, there is a shortcut key (Shift+Alt+F10) to include using statements for assemblies. A smart tag shows up at the end of the class name too, if the IDE can find the class.

Oops. That btw in my last comment was for C#.

I’ve been using Code Snippets via Resharper, so I’m looking forward to this being built in.

For example, I created a “Property” snippet so that when you name the private member “_someMember”, it automatically names the property “SomeMember”. (I noticed you’re an underscorer too). Just a bit less typing than the demo you showed.


I was experimenting with that when renaming variables, I didn’t realize it worked for adding assembly refs as well. I wonder why they made it such a contortion-inducing shortcut chord… not exactly easy to press.

This also works in VB.NET, but it changes the ref to “Net.WebClient” instead of an “Imports System.Net” statement … weird.

Another one of the great features MS Visual FoxPro had for years. Remember to thank YAG and his team for showing the VS.Net interface guys how to do things right in VS.Net 2005.

I use gif-gif-gif.

It’s so ancient I think it was written in hieroglyphics, but it still works like a champ for 256-color friendly captures…

Does anyone know of a snippet cheat sheet that I could post on my wall?

Chris - Cheat Sheet:

I 3 Code Snippets =D

Can someone provide the registration code to the GifgIfgiF program? it would be great help :slight_smile: