Collapse all #regions only(!) in C# (Visual Studio)

ygoe picture ygoe · Jun 3, 2015 · Viewed 76.5k times · Source

There's a number of keyboard shortcuts and menu commands to automatically expand or collapse all foldables in the current document. Ctrl+M, Ctrl+L toggles all foldables recursively, from the top namespace down to the inner methods and comments. Basically everything that has a [+] icon in the left margin. Ctrl+M, Ctrl+O does it bit less, but it still touches methods and comments inside the class.

I'm looking for a function that specifically only regards #region foldables and nothing else. Not namespaces, classes, comments, or methods. I really only want to fold those areas that are explicitly marked as such with the #region keyword.

Is there any hidden shortcut or an extension for that?

I'd prefer a keyboard solution, for Visual Studio 2015 (RC for now).

In case somebody asks why: I want to get an overview of the file, but immediately see all the details when I decide to look inside one region.


Update:

Solution in 2020

As this question has received many answers, some of them useless, others outdated, the working solution for Visual Studio 2019 can be found in this underappreciated answer here: https://stackoverflow.com/a/58999093/143684

Answer

Myz picture Myz · Mar 17, 2017

in Visual Studio 2017 I have to activate 'Collapse #regions when collapsing to definitions' in

Tools -> Options -> Text Editor -> C# -> Advanced

explicitly to collapse all when pressing Ctrl+M+O