How to create a 'surround with' type of snippet in Visual Studio 2010?

FiveTools picture FiveTools · May 5, 2011 · Viewed 16.8k times · Source

Is there a way to create a 'surround with' snippet in visual studio 2010? I know how to create a replacement type of snippet. A simple surround with snippet could surround a block of text with an asp:hyperlink. Similar to the way the default 'surround with' snippets can surround a block of code with an asp:panel.

Answer

DiamondBack picture DiamondBack · Oct 19, 2011

It turns out that there are some pre-defined ID's that are not well documented. Specifically For SurroundWith type snippets, there is an ID $selected$. So, for example, the code for the #if snippet is:

...
<Code Language="csharp">
    <![CDATA[#if $expression$ $selected$ $end$ #endif]]>
</Code>
...

The $end$ ID indicates where to place the cursor when the Surround function is complete. That's really all there is to it. Of course, remember to include SurroundsWith as the SnippetType

For more examples, try taking a look at the predefined snippets in C:\Program Files\Microsoft Visual Studio 10.0\\Snippets\1033\.