Surround with a Code Snippet

Tips Search

Surround with a Code Snippet

  • Comments 7

Keyboard:  CTRL + K, CTRL + S
Menu:  Edit -> IntelliSense -> Surround With
Command:  Edit.SurroundWith
Versions:  2008,2010
Published:  4/21/2010
Code:  vstipEdit0052

 

Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!

 

This is one that even people who know about snippets tend to forget.  You can actually put a snippet AROUND existing code.  Assuming you have some code selected:

image

 

Just press CTRL + K, CTRL + S:

image

 

Then type the statement you want to surround the code with.  In this case, I'll use an "if" statement:

image

 

Hit your TAB key once and you get your result:

image

 

Now you can put in your condition and any additional logic you want.  Pretty cool stuff!

  • Did this feature get removed from Visual Basic 2010? I can find "Surround With ..." in Visual Basic 2008 and Visual C# 2010 but not Visual Basic 2010.

    If so, I am curious as to why? It is a feature that I used a fair bit for inserting regions into existing code.

    It would be nice if you updated the tip to indicate that it does not apply to Visual Basic (if that is the conclusion).

    Thanks.

  • All I get is "The key combination (CTRL + K, CTRL + S) is bound to command (Surround With...) which is not currently available."

    I guess this doesn't work for C++, either. :(

  • Why is there features like this one, and it's not included in VB?

  • All -- So this feature is not currently available outside of C#.  There are snippet capabilities in VB / C++ but this isn't one of them.  I hope we will see this feature elsewhere as the team works on the next version of Visual Studio.

    Z

  • So the way they are going to kill VB is interesting.  "let's make the very good IDE that was in 2008 suck in 2010 and the C# IDE suck a bit less so folks will switch to C#".  It's an "Overton Window" kind of thing.

  • Actually, as I understand it, there is a big push internally to have all languages get equalized.  Not sure on the specifics but hope to hear more later on.

  • Ben

    probably you are debugging the code thats why you cant use the surround with ctrl k - s

Page 1 of 1 (7 items)
Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post