Surround with a Code Snippet

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:



Just press CTRL + K, CTRL + S:



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



Hit your TAB key once and you get your result:



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

Comments (8)

  1. Eddie says:

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


  2. Ben says:

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

  3. Uffe says:

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

  4. zainnab says:

    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.


  5. Charles Kincaid says:

    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.

  6. zainnab says:

    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.

  7. Ren says:


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

  8. eddyq says:

    There is a bug in this. If you have a line after the selection then ctrl k-s will  goof up the line following the selection. It doesn't cause a bug but it does goof up the looks of your code. E.g.:

    printf("this is a testn")

    printf("this is another linen");

    i = 10;

    Select the two "printf" lines and use ctrl k-s. It will become this:

    if (true)


       printf("this is a testn")

       printf("this is another linen");

    } i = 10;

Skip to main content