Did you know? You can now manage your snippet highlighting (Lisa Feigenbaum)

Did you know? You can now manage your snippet highlighting (Lisa Feigenbaum)

  • Comments 11

Do you use code snippets (introduced in VB 2005)? If you do, then you've probably noticed the green highlighting that stays around for the lifetime of the file. We've heard *a lot* of feedback that once you are done customizing the snippet, it is distracting to see this highlighting stay around. To address this, VB 2008 has improved the heuristics that determine when you are done using the snippet. It has also added some new commands that allow you to control whether or not the highlighting appears. Let's take a look at how the works in VB 2008...

Snippets can be inserted either from the snippet picker (Rt-click -> Insert Snippet) or from a shortcut. In VB 2008, all snippets with keyword shortcuts appear in intelliSense. Here's an example:

As I type 'pro', VB 2008 IntelliSense filters down to the matching items. Because the Property snippet's shortcut is a keyword ('Property'), it appears in intelliSense. In the tooltip, there is a note explaining how to insert the snippet from intelliSense. After tabbing twice, the Property snippet gets inserted:

The highlighted fields are called "snippet replacements". They indicate what I should change to adapt the snippet to my program.

There are a few other snippet features to be aware of... You can hover over a snippet replacement to get a tooltip explaining how to replace that field:

This is less critical for language snippets like the current Property example, but is quite useful for snippets that show how to do a particular task. It is also useful when writing snippets to share out to a group. It gives you a way to inform people about how to use your snippet.

Another interesting snippet feature is "linked replacements". Since certain fields in the snippet always have to stay in sync, VB links those fields so you only have to replace them once. For example, I'll replace the first field of the property snippet:

Now when I tab off of this field, the two other linked replacements get updated:

Next, I finish customizing my snippet:

Once I am done, it is distracting to continue seeing so much green. In VB 2008, as soon as I start typing outside of the snippet bounds, the highlighting will go away!

Note: In C#, the trigger that turns off highlighting is pressing Enter. In VB, the trigger is any edit outside the snippet bounds. At that point it is assumed that the snippet editing is done.

This improves the experience when you're done customizing the snippet. However, there may be times when you want to return to edit the snippet, and continue using the snippet features illustrated above! For that scenario, you can use some new editor commands. Return to the snippet that you want to use, and Rt-click.


Select "Show Snippet Highlighting" and the highlighting will return, along with all the functionality mentioned earlier: linked replacements, replacement tooltips, etc.

Once you are done with the snippet, you can make an edit outside the snippet bounds to hide the highlighting (as we saw earlier). You can also rt-click to use the reverse "Hide Snippet Highlighting" command:

And voila, the green goes away!


Lisa Feigenbaum

Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post
  • PingBack from http://oscarblog.justfree.com/thereplacements.html

  • Great post.  I did not know about the ability to show/hide snippet highlighting after initial edits.

  • Great news !! Snippet highlighting could be very annoying.

  • Well timed article, I'm having fun playing with the Code Snippets. Any chance of a blog on the code snippet keywords $seleced$ and $end$.

  • Very nice little post. I too, was unaware of the Show/Hide snippet highlighting. This is indeed a most useful feature. Thanks for the info.

  • The VB Team has a great article on snippets .  Well, first off, what exactly is a snippet? 

  • While I agree code snippets are a real productivity boost, but I am not crazy about the Visual Studio approach. I much rather prefer if it was drag and drop, like in dreamweaver/homesite.

    Lately I have been using  a tool called snip-it pro (http://www.snipitpro.com) instead.

  • 皆さんは、 VB 2005 で導入されたコード スニペットをお使いでしょうか。 お使いであれば、ファイルを使う間、あたりが緑色の強調表示だらけになることにお気付きでしょう。これに関するご意見は、実に多数いただきました。スニペットのカスタマイズが済んだ後は、この強調表示が邪魔だというのです。この問題に対処するため、

  • [原文作者]: Lisa Feigenbaum [原文链接]: #6 Did you know? You can now manage your snippet highlighting 你用过自动完成代码段么

  • Thanks for the info. I found it really useful.

  • great post sir..

    thanks for sharing. really helped a lot here.


Page 1 of 1 (11 items)