Keith finally learns how to use snippets

Security Briefs

Syndication

I'm probably the last person in the world to figure this out, but ever since I've been using VS 2005, I've been rather bummed that snippets never seemed to work for me.

Ever type the letter 'c' while writing C# source code and see that tempting cw snippet sitting there? It's obvious what it's for - if you can get it to expand, it'll expand to Console.WriteLine(FOO) and highlight FOO allowing you to type whatever it was you wanted to dump to stdout.

But what happens when you select the snippet you want with the mouse, or press <TAB> to do the same thing? Pretty much nothing. It completes to 'cw' and the Intellisense drop down disappears. now you're sitting there looking at a line of code that looks like this:

cw

Woohoo. Snippets are cool, aren't they?

If you didn't know that you need to hit <TAB> at this point to expand the snippet, you'd be wondering what the fuss was all about (as I was until tonight). So ultimately what you need to do is type

cw <TAB> <TAB>

...where the first <TAB> simply gets rid of the Intellisense drop down, and the second <TAB> actually performs the expansion. Well I feel stupid now, and I hope that at least one other person is as dim as me, otherwise this post will have been simply exposing my naivete :)

Is it just me, or is this somewhat unintuitive? When the intellisense feedback disappeared, I simply assumed the fireworks were over and typed out Console.WriteLine by hand. But never again!


Posted Dec 19 2005, 06:54 PM by keith-brown
Filed under:

Comments

James Kovacs wrote re: Keith finally learns how to use snippets
on 12-19-2005 7:34 PM
Very amusing, Keith. I wrote a very similar post about two weeks ago where I claimed to be the second to last developer to finally figure out snippets. A lot of developers have approached me claiming to be the last. Seems like you too can join that merry club!

http://www.jameskovacs.com/blog/ALapAroundCodeSnippetsInVS2005.aspx

I would agree with you. The feature is not intuitive to find, but once you find it, it's pure gold.
shawn cicoria wrote re: Keith finally learns how to use snippets
on 12-20-2005 4:35 AM
where was this documented :)

In the same boat. Somebody was keeping it a secret.
Patrick Foley wrote re: Keith finally learns how to use snippets
on 12-20-2005 6:41 AM
I wonder what the appropriate usability fix would be - perhaps this is a job for a little box that pops up after the first tab prompting you to "hit <TAB> again to expand the snippet" with a "don't show this again" checkbox on it.

But I can't figure out why it wouldn't just expand after the Intellisense bit - is there ANY scenario where I would choose a snippet from Intellisense and NOT want it to expand?

Odd.
theCoach wrote re: Keith finally learns how to use snippets
on 12-20-2005 10:25 AM
+1, although in my defense, I have had very little time with 2005.
Ian Griffiths wrote re: Keith finally learns how to use snippets
on 12-20-2005 2:16 PM
You're not alone - I only discovered the Tab-tab shortcut about a month ago. (Despite the fact that it's exactly what you do for some other expansions. Wanna implement an interface? Tab once to complete the interface name from IntelliSense (assuming you've not yet typed in the whole thing), tab again to implement. Wanna handle an event? Tab once for the delegate instantiation, tab again for the stub generation.)

Indeed, I had even learned the long-winded alternative shortcut for expanding snippets. (I've already forgotten it now that I know Tab-Tab... But I think it might have been Ctrl-K, Ctrl-X.)
flipdoubt wrote re: Keith finally learns how to use snippets
on 12-30-2005 6:13 AM
I had no idea how to expand snippets till I read this, so I must be more dim than you. Thanks.
William Stacey wrote re: Keith finally learns how to use snippets
on 01-19-2006 1:28 PM
I am a dim member. No longer. :-)
Ram wrote re: Keith finally learns how to use snippets
on 03-28-2007 10:16 PM
Excellent Guys........I had a harrowing time figuring out what exactly is code snippet tab while working with Microsoft Virtual Labs.

Thanks Guys!!!! Quite a good work :)

Ram
Dewy wrote re: Keith finally learns how to use snippets
on 04-08-2008 6:53 AM
Thanks a whole lot, I may be like 2 years behind everyone else in figuring this out, but I just couldn't do it. At least I am not the only one.

Cheers
Dewy

Add a Comment

(required)  
(optional)
(required)  
Remember Me?