Andrej Tozon's blog

In the Attic

NAVIGATION - SEARCH

VS2005 Code Snippets

The basic idea behind Visual Studio 2005 Code snippets is to help developers write more code by actually typing less, while inserting templated code chunks or patterns, which we repeatedly use in our day-to-day coding.

Code snippets are easily accessible from your IDE. You can either type their (abbreviated) name and do some TAB tapping, or right-click in your code window and select:

  • Insert Snippet... [for insertion]
  • Surround With... [surrounds selected code with the snippet code]

If you prefer using keyboard shortcuts: use Ctrl+K, Ctrl+X for insertion and Ctrl+K, Ctrl+S for surround with.

Writing custom snippets is also easy; you'll find the recipe with all ingredients listed in the MSDN documentation. Try it, it's fun. As an example, I created a simple snippet, which creates the string.IsNullOrEmpty() test block:

Inserting snippet

Completing snippet insertion

You can download this snippet from here. Unzip the .snippet file and copy it to "My Documents\Visual Studio 2005\Code Snippets\Visual C#\My Code Snippets" folder. Enjoy.

[Also, feel free to peek around for other code snippets]

[Update: create code snippets faster with the Code Snippets Editor or Snippy /thanks, D.]