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
0 comments
Be the first to start the discussion.