Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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


Ctrl+M+O will collapse all.

Ctrl+M+L will expand all. (in VS 2013 - Toggle All outlining)

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.

Right click in editor -> Outlining to find all options. (After disabling outlining, use same steps to enable outlinging.)


To collapse regions : Tools > Options > Text Editors > C# > Advanced > Check "Collapse #regions when collapsing to definitions"

Collapse #regions image


The Visual Studio extension Productivity Power Tools 2015 from Microsoft has a feature called Quick Launch Tasks that adds new commands to the Quick Launch menu. One of them is CollapseRegions and it does exactly that.

The opposite command is ExpandRegions and it expands all regions for quick browsing of the entire file. These commands can be used pretty quickly by pressing the CtrlQ hotkey and typing Coll resp. Exp, then pressing Enter (supposed you don't have other commands with the same prefix).


I know this is an old question, but here's an update for visual studio 2019:

The Quick Tasks solution from @ygoe's answer does not work for Visual Studio 2019, because that version changed the way the Quick Task bar searches. Plus it was never the preferred solution to the original question, since you needed to type a quick action instead of having a keyboard shortcut.

I found a different solution on the marketplace which does exactly the collapsing and expanding of all regions in the currently opened file with keyboard shortcuts: Collapse Region

From the extension page:

Default key bindings are (Ctrl+R, Ctrl+Num+) and (Ctrl+R, Ctrl+Num-). Can be changed in Tools->Options->Environment->Keyboard.


tick the Checkmark in Settings -> TextEditor -> C# -> Advanced -> (section Outlining) Collapse #regions when collapsing definitions.

then right click in the editor > outlining > collapse to definitions