Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 900
FiveTools Avatar asked May 05 '11 16:05

FiveTools


People also ask

What is a snippet Visual Studio?

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.


1 Answers

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\.

like image 83
DiamondBack Avatar answered Oct 06 '22 14:10

DiamondBack