Using Hide Selection


Keyboard:  CTRL + M, CTRL + H
Menu:  Edit -> Outlining -> Hide Selection
Command:  Edit.HideSelection
Versions:  2010
Published:  3/22/2010
Code:  vstipEdit0036

 

This is a new feature in VS2010 that absolutely rocks!  Let’s say you have a chunk of code like this:

image

 

Notice that Outlining only allows you to collapse the entire member by default (minus sign in the upper left-hand corner).  What if you want to, say, collapse the “if” statements at the top?  In prior versions you were out of luck but NOW you can do it.  First, select the chunk of code you want to hide:

image

 

Now either press CTRL + M, CTRL + H or go to Edit -> Outlining -> Hide Selection on your Menu Bar to get this:

image

 

Congratulations!  You have successfully collapsed a custom region of code!  Now you can expand and collapse the custom area as long as you like. 

Comments (5)

  1. blacksjasone says:

    Thanks for giving some description to using hide selection.

  2. ray says:

    That’s great. DreamWeaver offered this function long before, it even shows a minus sign on both ends of the outline so that you can click to collapse selection.

    Anyway, it’s good to see that finally comes to VS10.

  3. Scott Dorman says:

    This is really nice. Now, if it could just automatically do this for control structures (if, while, switch, etc.) it would be even better.

    By the way, to unhide the selection (so it no longer automatically gets folded), use Ctrl+M, Ctrl+U or go to Edit -> Outlining -> Stop Hiding Current.

  4. zainnab says:

    Scott :)

    You are absolutely right!  I thought I updated this post with that information but looks like I put in the tag but not the content.  The post has been updated with the new info.

    Z

  5. Joey Morgan says:

    I am old enough and ADD enough that I actually LIKE regions. I find it especially useful when I inherit legacy code where I am not permitted to refactor to reorganize. In rare cases, I want to collapse nested loops or a switch section, and this works very well for me. (VS2013 Ultimate). I appreciate you sharing this information. The community of MS Developers is one reason I can be so successful. Rock on!