poudigne
poudigne

Reputation: 1766

Collapse ALL #region in Visual Studio 2012

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.

Upvotes: 25

Views: 15972

Answers (6)

Tony Pulokas
Tony Pulokas

Reputation: 475

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.

Upvotes: 3

james
james

Reputation: 593

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

Upvotes: 5

Felix
Felix

Reputation: 1016

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?

Upvotes: 23

Val K
Val K

Reputation: 105

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

Upvotes: 3

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

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

Upvotes: 2

Vahid Mehrabi
Vahid Mehrabi

Reputation: 674

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

Upvotes: 7

Related Questions