Inserting Code Snippets
Keyboard: CTRL + K, CTRL + X
Menu: Edit -> IntelliSense -> Insert Snippet
Command: Edit.InsertSnippet
Versions: 2008,2010
Published: 4/20/2010
Code: vstipEdit0051
Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!
Let's talk about snippets. For some reason, even though these have been around for a while, people still don't have this baked into their brain. So let's assume you are in the editor:
C#
VB
And you want to crank out an "if" statement. You can type it out but that would be the hard way out. Why not just use a snippet? There are several ways to do this:
Just type "if" and press TAB twice:
C#
The piece of paper indicates this is a snippet in C#.
VB
In VB you won't have the piece of paper but will have a note in the tooltip that indicates this is a snippet:
Press CTRL + K, CTRL + X or Right-Click and choose Insert Snippet or Go to Edit -> IntelliSense -> Insert Snippet on the Menu Bar:
C#
You will get this prompt to Insert Snippet.
Go to "Visual C#" then press ENTER:
Then type "if" and press ENTER:
VB
You will get the same prompt as you did in C# to start but the path is different. Go to "Code Patterns [.]" then press ENTER:
Go to "Conditionals and Loops" then press ENTER:
No matter which option you choose the result is essentially the same:
C#
VB
You can now type in your condition and then the rest of your logic. Enjoy!
Comments
Anonymous
April 19, 2010
I know why peaple don´t use this... look at that! ctrl+K, ctrl+x plus find the snipet inside those giant categories list... I dont know but should be an easer way to do this...Anonymous
April 21, 2010
I like code snippets and surround with, they have helped me learn some C#