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

后端 未结 4 1628
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 02:25

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 eve

相关标签:
4条回答
  • 2020-12-09 02:43

    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.

    0 讨论(0)
  • 2020-12-09 02:52

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

    0 讨论(0)
  • 2020-12-09 03:02

    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
    
    0 讨论(0)
  • 2020-12-09 03:05

    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.

    0 讨论(0)
提交回复
热议问题