221

在 Visual Studio 中,如果我打开了一个代码文件,我可以按CTRL+MCTRL++MO折叠所有代码块、区域、命名空间等。

我如何做相反的事情并扩展一切?

我已经用谷歌搜索了这个,但似乎找不到有效的快捷方式!

4

7 回答 7

371

折叠到定义

CTRL+ M,O

展开所有大纲

CTRL+ M,X

展开或折叠所有内容

CTRL+ M,L

这也适用于其他语言,如 TypeScript 和 JavaScript

于 2012-12-27T08:29:45.323 回答
136

如您所见,有几种方法可以实现这一目标。

我个人使用:

展开全部:CTRL+ M+L

全部折叠:CTRL+ M+O

奖金:

在光标位置展开/折叠:CTRL+ M+M

于 2014-09-29T08:56:03.957 回答
32

视觉工作室 2015:

Tools > Options > Settings > Environment > Keyboard

默认值:

Edit.CollapsetoDefinitions:CTRL + M+O

Edit.CollapseCurrentRegion: CTRL + M+CTRL + S

Edit.ExpandAllOutlining: CTRL + M+CTRL + X

Edit.ExpandCurrentRegion: CTRL + M+CTRL + E

我喜欢设置和使用 IntelliJ 的快捷方式:

Edit.CollapsetoDefinitions:CTRL + SHIFT + NUM-

Edit.CollapseCurrentRegion:CTRL + NUM-

Edit.ExpandAllOutlining:CTRL + SHIFT + NUM+

Edit.ExpandCurrentRegion:CTRL + NUM+

于 2015-11-04T12:38:34.033 回答
22

您可以使用Ctrl+MCtrl+P

它被称为 Edit.StopOutlining

于 2012-12-27T08:30:14.250 回答
13

对于折叠,您可以尝试CTRL++并使用M++展开。这适用于 VS2008。OCTRLMP

于 2014-09-10T04:56:06.003 回答
8

转到工具->选项->文本编辑器->c#->高级并取消选中第一个复选框当文件打开时进入大纲模式。

这将永远解决这个问题

于 2014-10-30T12:21:50.930 回答
5

我一直希望 Visual Studio 包含一个仅折叠/展开区域的选项。我有以下宏可以做到这一点。

Imports EnvDTE
Imports System.Diagnostics
' Macros for improving keyboard support for "#region ... #endregion"
Public Module CollapseExpandRegions
' Expands all regions in the current document
  Sub ExpandAllRegions()

    Dim objSelection As TextSelection ' Our selection object

    DTE.SuppressUI = True ' Disable UI while we do this
    objSelection = DTE.ActiveDocument.Selection() ' Hook up to the ActiveDocument's selection
    objSelection.StartOfDocument() ' Shoot to the start of the document

    ' Loop through the document finding all instances of #region. This action has the side benefit
    ' of actually zooming us to the text in question when it is found and ALSO expanding it since it
    ' is an outline.
    Do While objSelection.FindText("#region", vsFindOptions.vsFindOptionsMatchInHiddenText)
        ' This next command would be what we would normally do *IF* the find operation didn't do it for us.
        'DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
    Loop
    objSelection.StartOfDocument() ' Shoot us back to the start of the document
    DTE.SuppressUI = False ' Reenable the UI

    objSelection = Nothing ' Release our object

  End Sub

  ' Collapses all regions in the current document
  Sub CollapseAllRegions()
    Dim objSelection As TextSelection ' Our selection object

    ExpandAllRegions() ' Force the expansion of all regions

    DTE.SuppressUI = True ' Disable UI while we do this
    objSelection = DTE.ActiveDocument.Selection() ' Hook up to the ActiveDocument's selection
    objSelection.EndOfDocument() ' Shoot to the end of the document

    ' Find the first occurence of #region from the end of the document to the start of the document. Note:
    ' Note: Once a #region is "collapsed" .FindText only sees it's "textual descriptor" unless
    ' vsFindOptions.vsFindOptionsMatchInHiddenText is specified. So when a #region "My Class" is collapsed,
    ' .FindText would subsequently see the text 'My Class' instead of '#region "My Class"' for the subsequent
    ' passes and skip any regions already collapsed.
    Do While (objSelection.FindText("#region", vsFindOptions.vsFindOptionsBackwards))
        DTE.ExecuteCommand("Edit.ToggleOutliningExpansion") ' Collapse this #region
        'objSelection.EndOfDocument() ' Shoot back to the end of the document for
        ' another pass.
    Loop
    objSelection.StartOfDocument() ' All done, head back to the start of the doc
    DTE.SuppressUI = False ' Reenable the UI

    objSelection = Nothing ' Release our object

  End Sub
End Module

编辑:现在有一个名为 Edit.ToggleOutliningExpansion (Ctrl+M, Ctrl+M) 的快捷方式可以做到这一点。

于 2015-01-26T15:29:00.013 回答