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.
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code. Code snippets are small blocks of reusable code that can be inserted in a code file using a right-click menu (context menu) command or a combination of hotkeys.
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\.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With