views:

5189

answers:

7

In Visual Studio (2008) there a command to collapse/expand all the sections of code in a file?

A: 

If you mean shortcut then

CTRL + "M" + "M": This one will collapse the region your cursor is at whether its a method, namespace or whatever for collapsing code blocks, regions and methods. The first will collapse only the block/method or region your cursor is at while the second will collapse the entire region you are at.

http://www.dev102.com/2008/05/06/11-more-visual-studio-shortcuts-you-should-know/

Shoban
+26  A: 

CTRL + M + O will collapse all.

CTRL + M + L will expand all.

CTRL + M + P will expand all and disable outlining.

CTRL + M + M will collapse/expand the current section.

These options are also in the context menu under Outlining.

Bob
You can also right click in the editor an select: Outlining -> Toggle All Outlining
LBushkin
double-check your expand all - i think it should be M+L and not M+P.
Scott Ivey
I just gave L a try, that works too, thanks, I'll update my post
Bob
+1 - good answer
Scott Ivey
I love CTRL +M +P We have an id**t that nests regions 4 deep.
Jim Evans
ctrl+m ctrl+o is "collapse to definitions" which doesn't work when editting an xml file. For me ctrl+m ctrl+l expands all and collapses all (as toggle), but not always. I have one file open where it works and one where it only expands all, but not collapse all. Both are xml files. No idea why.
Matthijs Wessels
+3  A: 

Ctrl-M, Ctrl-L collapses/expands (toggles) all regions.

M4N
This doesn't work for my under VB.NET; it's not recursive.
Richard Morgan
+1  A: 

Yes there's a keystroke command, see this link for a how to:

link

Colin
+2  A: 
* Fold/Unfold the current code block – Ctrl+M, Ctrl+M
* Unfold all – Ctrl+M, Ctrl+L
* Stop outlining – Ctrl+M, Ctrl+P
* Fold all – Ctrl+M, Ctrl+O
AvatarOfChronos
+1  A: 

Are you refering to the toggle outlining?

You can do Control-M then Control-L for toggle all outlining

Jason Heine
+1  A: 

CTL+M+L expands all CTL+M+O collapses all

Check here if you're looking for other shortcuts - these 2 are just a few of the many that are available.

Scott Ivey
Nice link, very thorough!
Bob
As I commented in the top answer, ctl+m+o collapses to definition which doesn't work for xml files. ctl+m+l should toggle it, but for me it sometimes does and sometimes doesn't.
Matthijs Wessels