Collapsing Your Code with Outlining

Tips Search

Collapsing Your Code with Outlining

  • Comments 16

Keyboard:  CTRL + M, CTRL + M
Menu:  Edit -> Outlining -> Toggle Outlining Expansion
Command:  Edit.ToggleOutliningExpansion
Versions:  2008,2010
Published:  3/15/2010
Code:  vstipEdit0029


By default, Outlining is enabled in Visual Studio.  It's the line you see with the boxes to indicate the status of the area (collapsed or expanded):



You can collapse areas of code to get them out of your way so you can focus on other areas.  There are four ways to do it:

  1. Click on the minus sign to collapse an area of code:


    NOTE:  In VS2010 it now highlights the area that will be collapsed as seen here.  A very cool feature.  If you don't like the highlighting color you can go to Tools -> Options -> Environment -> Fonts and Colors -> Collapsible Region to change it.

  2. VS2010 ONLY:  Click ANYWHERE on the vertical line in the highlighted region.  In other words, you can now collapse a region from anywhere in that region:
  3. Click anywhere in the area to be collapsed and hit CTRL + M, CTRL + M
  4. Click anywhere in the area to be collapsed and go to Edit -> Outlining -> Toggle Outlining Expansion on the Menu Bar


Once collapsed, the code area will look like this:


  • Hey Now Zain,

    Nice one, also after collapsing by Ctrl + M, Ctrl + O on a code behind file a nice one to know is how to:

    expand Ctrl + M, Ctrl + P

    Also combining these with #region's are useful too.

    Thx 4 the info,


  • Super. Now how do I turn this feature off? I could turn it off in VS 2005.

  • There was a "feature" in older versions that would take out outlining when you removed the selection margin from the options.  In 2010, that doesn't exist so you have to remove it on a per-document basis.  You can use CTRL+M, CTRL+P ( which is Edit | Outlining | Stop Outlining on the menu bar).  To turn it off.


  • After doing Ctrl+M Ctrl+O, which collapses all, if I switch to a different document tab and switch back, everything auto-expands again. I want it to stay collapsed. Is there a way to keep it from auto-expanding every time I switch pages ?

  • it would be much better to collapse individual scopes (eg.: collapsing a switch statement)

  • Rui - while it doesn't do it automatically, you CAN hide individual scopes yourself with hide selection:

    Ed - That is not normal behavior if it persists that might indicate a problem with the SUO file.


  • I have a problem with 2010 outlining,,

    in 2008 it used to collapse the newline too but in 2010 it leaves a space in between each collapsed segments. that's pretty annoying in terms of readability and makes the collapsed page longer than it should.

    Does anyone know how to fix it?

  • Rei :)

    There is no way that I am aware of to reduce the space between collapsed regions.


  • How to keep comments on multiple line expanded because if I have 2 lines of comments, it adds a + and I don't want it.  I want to keep my comment visible for all lines.

    This is only for comments not the code

  • Please add an Option to *not outline* comment blocks. This is super annoying. I just want to be able to right-click and Collapse all and see the comments above methods and the method {...}.  But because it treats multi-line comments as an outline block it collapses like 1/2 my method comments.

  • +1 for Doug's comment, I've wanted an option to 'not outline comments' since I first discovered the feature..

  • Please add an Outline By Filter so that auto outlining can outline every line of code that matches a text filter.

  • use this to have your comments not outlined :

       ''' <summary>

       ''' What is this Sub for....

       ''' </summary>

       ''' <param name="parameter_1">Description of parameter_1</param>

       ''' <param name="parameter_2">Description of parameter_2</param>

       ''' <param name="parameter_n">Description of parameter_n</param>

  • ... in C# use

           /// <summary>


           /// </summary>

           /// <param name="args"></param>

  • What is the shortcut to toggle outline on cshtml views files on mvc project ?

Page 1 of 2 (16 items) 12
Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post