Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

Did you know... You can insert a code snippet via its shortcut keyword - #105

Update: thanks to Bill for catching that VB doesn't show snippet shortcuts in the statement completion.  I've updated the VB picture below to better illustrate what is going on.  Also, check out Bill's post, as he talks about using the '?' to insert snippets. 

This is probably a much better tip than the previous two.  Code Snippets have the support to be given a "shortcut", usually an abbreviated version of the code snippet name that you can type into the editor and hit tab to insert.

To insert, simply type in the name of the snippet, e.g. "for", then hit tab.  Note that if statement completion is open, you'll have to hit tab twice to insert the snippet.

In both Visual Studio 2005 and 2008, you will be able to see C# Code Snippet shortcuts in the Statement Completion window.  Below is the for snippet displayed within the Statement Completion window.  Note the snippet icon to the left.

For Snippet In StatementCompletion

In Visual Studio 2008, you won't see VB snippets in the statement completion window, but you will see a note in the tooltip when you can hit tab twice to insert the corresponding snippet.

VB For keyword in statement completion

Technorati tags: ,
Posted: Wednesday, December 12, 2007 3:00 AM by saraford

Comments

Bill_McC said:

VB does NOT display snippets in the statement completion window, it only displays namespaces, types, members and Keywords.

Also note that with VB you cannot insert a snippet by typing it's name and hitting tab if the shortcut is a substring of anything that displays in the completion window. (you could in 2005, but this was broken intentionally for 2008)

# December 12, 2007 6:54 AM

@ Head said:

Sara Ford writes about inserting snippets in VB and C#. Unfortunately, Sara has got it quite right. In

# December 12, 2007 7:28 AM

Noticias externas said:

All code snippets are found in the Code Snippet Manager. It is found at Tools - Code Snippet Manager

# December 13, 2007 6:51 AM

Sara Ford's WebLog said:

All code snippets are found in the Code Snippet Manager. It is found at Tools - Code Snippet Manager.

# January 15, 2008 1:11 AM
New Comments to this post are disabled
Page view tracker