Surround-with Code Snippets in Visual Studio

By | January 8, 2012

Surround with” is a very nice features in Visual Studio IDE. The overall objective of this features is to surround the code snippets with a set of statement or controls very easily. Let’s assume that, you have set of code block which you want to put inside a if statement, so instead of writing the statement complete, first select the code block, right click and select “Surround with” from context menu.

This will display the available snippet for surround with.  Select any one them ( As part of this example we select if ) as shown in below:


This will automatically wrap the selected code snippet with the “Surround with” snippet.  As show in below image, select code blocked surrounded with “if” statement.


If you are an ASP.NET developer, you can use the same features in HTML Markup as well.  Select the HTML Code Block and select “Surround With” from context menu.


This will launch similar code snippet option for html control. Select the snippet and you are done !


Not only html controls, the similar snippet is available for ASP.NET Control as well. image

You can do this using keyboard by using short cut key “CTRL +K , CTRL + S”.


Overall this features is very handy and also save lots of time during development. So go ahead and give a try :)

Cheers !