Table of Contents
What is a snippet?
Snippets are small little bits of code which can be inserted into your source files through the use of short names. There are many snippets that come built into Visual Studio for creating everything from new classes to for loops.
The snippets provided on this page will work with Visual Studio 2005 and 2008.
How do I use a snippet?
To use a snippet, inside of your text editor in Visual Studio, type the name of the snippet, and then press TAB. (Note: if Intellisense is active, you may need to hit TAB twice: once to dismiss Intellisense and once to activate the snippet).
Example of a snippet, pre-activation:
Once the snippet is activated, the template is expanded into your text editor. Snippets will often have replaceable values. The first replaceable value will be highlighted so you can replace it. You can switch between the replaceable values with the TAB key. When you're finished changing all the replaceable values, pressing ENTER will take you to the final insertion point of the snippet.
Example of a snippet, upon activation:
How do I install a snippet?
Snippets are installed by copying the .snippet file into the proper directory. Navigate to your My Documents folder, then to the "Visual Studio 2005" or "Visual Studio 2008" directory. Then navigate to the "Code Snippets" directory, to the language of the snippet, and finally to the "My Code Snippets" directory.
Example of the snippets path, with the C# "fact" snippet installed:
Snippet: fact
| Description: | Creates a new fact method |
| Last Updated: | December 1, 2007 |
| Download: | C#, VB |
Snippet in C#:
[Fact]
public void FactName()
{
}
Snippet in VB:
<Fact()> _
Public Sub FactName()
End Sub