Ivan
Ivan

Reputation: 64207

How to configure Visual Studio to collapse all regions by default?

When I open a code file in a new code window, I press Ctrl+M,O to collapse everything there. As far as I know this can be done by default, without need to press anything every time. I think I did it once, but can't remember where was this option located.

Upvotes: 38

Views: 18455

Answers (4)

nickmoriarty
nickmoriarty

Reputation: 1263

As a last resort if you can't get it to work with settings, you can also write a macro to do this. Check out this link for an example on this.

Here is the main information from the link:

You can open the Macro IDE by going to Tools->Macros->Macros IDE. There should be a module called EnvironmentEvents in project MyMacros. This code should be added to the EnvironmentEvents Module:

Private opened As Boolean

    Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
        If GotFocus.Document Is Nothing Then
            Return
        End If
        If GotFocus.Document.FullName.EndsWith(".cs") And opened = True Then
            DTE.ExecuteCommand("Edit.CollapsetoDefinitions")
        End If
        opened = False
    End Sub

    Private Sub DocumentEvents_DocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened
        opened = True
End Sub

Upvotes: 3

CoderTao
CoderTao

Reputation: 3991

For the record, I found unchecking the 'Enter Outlining Mode' option would disable all outlining, which was undesirable.

I did find this extension though: https://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca , the "I Hate #Regions" extension. Available for VS2010-2015, and so far seems to work as advertised.

Upvotes: 0

agent-j
agent-j

Reputation: 27903

This is possible. Go to the Tools menu, then select options.

Text Editor
 \ C#
   \ Advanced

The option is called "Enter outlining mode when files open." When outlining mode is enabled, your regions are collapsed by default.

Upvotes: 32

Simon Wilson
Simon Wilson

Reputation: 10424

Have you tried Tools\Options\Text Editor\C#\Advanced and check the "Enter outlining mode" when files open?

Upvotes: 8

Related Questions