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

2019-01-31 10:44发布

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.

5条回答
Explosion°爆炸
2楼-- · 2019-01-31 10:57

in Visual Studio 2017 I have to activate 'Collapse #regions when collapsing to definitions' in Options -> Text Editor -> C# -> Advanced explicitly to collapse all when pressing Ctrl+M+O

查看更多
Juvenile、少年°
3楼-- · 2019-01-31 10:58

Looks like the closest thing is Ctrl+M, Ctrl+S

Which will collapse the current region you are in, while Ctrl+M, Ctrl+E will expand the current region you are in.

List of default keyboard shortcuts:

https://msdn.microsoft.com/en-us/library/da5kh0wa(v=vs.140).aspx

查看更多
beautiful°
4楼-- · 2019-01-31 11:05

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.)

查看更多
混吃等死
5楼-- · 2019-01-31 11:08

I recommend using the free Visual Studio extension "Menees VS Tools Extension for Visual Studio." Just search for it in Tools --> Extensions and Updates in Visual Studio. Once installed you just have to hit Ctrl+M+K and just the regions will be collapsed. Here is their website https://marketplace.visualstudio.com/items?itemName=BillMenees.MeneesVSTools2013

To edit the settings look under Tools --> Options --> Menees VS Tools --> General.

查看更多
萌系小妹纸
6楼-- · 2019-01-31 11:09

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).

查看更多
登录 后发表回答