In Visual Studio 2005, we introduced code snippets.  The VS Editor Team Blog has a nice write-up on code snippets, if you want to learn more instead of waiting for a tip here and there from me =)

So we’re going to start the code snippet tip series with how to actually insert a code snippet.  The keyboard shortcut is Ctrl+K, Ctrl+X.  It is bound to the command Edit.InsertSnippet, in case your mileage varies, depending on your configuration settings.

I’m going to use C# for today’s tip, but this applies to all languages that support code snippets.  When I invoke the Edit.InsertSnippet command, the code snippet insertion UI pops up.  Did you know… (the real tip here) that the snippet picker allows for type-ahead scrolling.  Note how I started typing "#re" on the line.  (oh, the fun i had testing this… but i digress…)

Code Snippet Insertion UI

Additional keystrokes:

  • You can hit tab to auto-complete the word.  If the word happens to be the code snippet (and not a folder), pressing tab will insert it.
  • You can also hit Shift+Tab to navigate back to the previous word (my contribution to the insertion UI)

Technorati tags: VS2005Tip, VS2008Tip