在Visual Studio中,如果我打开了一个代码文件,我可以按CTRL + M或CTRL + M + O来折叠所有的代码块、区域、名称空间等。
我怎么做相反的事情,扩大一切?
我在谷歌上搜索过,但似乎找不到一个有效的快捷方式!
在Visual Studio中,如果我打开了一个代码文件,我可以按CTRL + M或CTRL + M + O来折叠所有的代码块、区域、名称空间等。
我怎么做相反的事情,扩大一切?
我在谷歌上搜索过,但似乎找不到一个有效的快捷方式!
分解到定义
CTRL + m, o
展开所有大纲
CTRL + m, x
展开或折叠所有内容
CTRL + m, l
这也适用于其他语言,如TypeScript和JavaScript
如您所见,有几种方法可以实现这一点。
我个人使用:
全部展开:CTRL + M + L
折叠全部:CTRL + M + O
奖金:
在光标位置展开/折叠:CTRL + M + M
我一直希望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
编辑:现在有一个称为编辑的快捷方式。ToggleOutliningExpansion (Ctrl+M, Ctrl+M)这样做。
Visual Studio 2015:
Tools > Options > Settings > Environment > Keyboard
默认值:
编辑。定义:CTRL + M + O
Edit。CollapseCurrentRegion: CTRL + M +CTRL + S
编辑。expandalloutline: CTRL + M + CTRL + X
编辑。ExpandCurrentRegion: CTRL + M + CTRL + E
我喜欢设置和使用IntelliJ的快捷方式:
)一。崩溃定义:ctrl + SHIFT + num-
)一。CTRL + NUM-
)一。扩展概述:ctrl+shift+num+
)一。展开currentregion: CTRL + NUM+