25

First of all, no CTRL+M, CTRL+O is not the answer. For me, this is collapsing #Region, ///Comments, and Methods and I hate that.

I'd like to collapse/expand ONLY #region sections. I am using Visual Studio 2012 and Resharper.

Daniel
  • 10,864
  • 22
  • 84
  • 115
poudigne
  • 1,694
  • 3
  • 17
  • 40
  • Possible duplicate of [Visual Studio - Command to collapse all sections of code?](http://stackoverflow.com/questions/982677/visual-studio-command-to-collapse-all-sections-of-code) – Alias Varghese Apr 28 '16 at 08:29
  • 1
    @AliasVarghese That 'duplicate' provides an answer which OP explicitly says they do not want. – Rob Apr 29 '16 at 00:54

6 Answers6

23

ctrl+m, ctrl+s will collapse the current region. You can select multiple regions manually and collapse them that way.

Since the command "Collapse all open region" doesn't exist, you could always try to create a new one; In that case, check out this post: How to add commands to Visual Studio 2012?

Community
  • 1
  • 1
Felix
  • 1,006
  • 8
  • 22
7

You can't collapse just regions, but the shortcut key chord: ctrl+m, ctrl+l will do it for everything.

Daniel
  • 10,864
  • 22
  • 84
  • 115
Vahid Mehrabi
  • 598
  • 10
  • 19
5

You can do this by installing the Menees VS Tools extension. It's available through the Visual Studio Gallery as well (in VS2013: Tools > Extensions and Updates... > Online > [Type Menees into the search box])

jimmyjudas
  • 581
  • 7
  • 13
3

Highlight everything CTR+A Then CTR+m CTR-m (2 times!!)

L-Ray
  • 1,637
  • 1
  • 16
  • 29
Val K
  • 105
  • 8
3

In an answer to a similar question Ray Pietrzak posted code for a macro that will do this. I used the Visual Commander extension to create a new "command", and I pasted Ray's code for the ExpandAllRegions and CollapseAllRegions methods into the command. I modified both methods so that they take a "DTE" parameter like so:

  Sub ExpandAllRegions(DTE As DTE2)

and

  Sub CollapseAllRegions(DTE As DTE2)

and I edited the Run method of the command like so:

  Sub Run(DTE As DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
      CollapseAllRegions(DTE)
  End Sub

The command can then be added to menu, toolbar, or keyboard shortcut.

Community
  • 1
  • 1
Tony Pulokas
  • 465
  • 5
  • 12
2

Unfortunately this isn't possible without writing your own Visual Studio extension that leverages the IDE. You can start here on MSDN.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232