Temporary Snippets in Visual Studio

Despite being a long-term user of Visual Studio, various versions and with various languages, I've just found a feature that I could have been using for years...

Often, as a programmer, as a presenter, as a trainer, I need small, throw-away, code snippets. Let me be clear that I don't mean permanently useful pieces of code as in Visual Studio snippets. I mean a temporary collection of small fragments of code that I will use a few times, and can then be discarded.

For throw-away snippets, my tool of choice has until now been Notepad. Copy and paste then works a treat. It is not a very high-tech solution, and there are obvious inconveniences. But now, my feeble brain now holds this technique:

Drag code to the Visual Studio Toolbox...

Drag...

...now that can be used as a snippet by dragging it back onto the source pane!

...and Drop

Since late 2005, I've used Visual Studio for more than 5 days out of every seven, and I never knew this was possible! Some other useful features took a long time to discover, like Ctrl+K-X for auto-formatting. For at least 2 years I (and many of my colleagues - as this was a common gripe) reformatted code by retyping the final "}" in the block. But, nothing like this toolbox trick.

I don't think I'm the only person who has missed this feature, as demonstrated by this question on stackoverflow where I discovered it.

Sara Ford's weblog used to offer a "Visual Studio tip of the day", and I now notice that she described this tip, in a round-about-way back on June 6th, 2005. I obviously missed that one! Sadly, Sara Ford now gives tips about the nearly-wholly uninteresting CodePlex site.

What other hugely useful features of Visual Studio am I blissfully unaware of?

2 comments

  1. Did you try snippet compiler instead of notepad :) http://www.sliver.com/dotnet/SnippetCompiler/

    rebolturial Fri, 19 Jun 2009

  2. Thanks for the suggestion.
    SnippetCompiler is interesting, but doesn't actually solve my underlying desire here.

    Stewart Fri, 19 Jun 2009