Ответ 1
Свернуть в определения
CTRL + M, O
Развернуть все очертания
CTRL + M, X
Развернуть или свернуть все
CTRL + M, L
Это также работает с другими языками, такими как TypeScript и JavaScript
В Visual Studio, если у меня есть файл кода, я могу нажать CTRL + M или CTRL + M + O, чтобы свернуть все блоки кода, регионы, пространства имен и т.д.
Как я делаю противоположное и расширяю все?
У меня есть Googled это, но не похоже, чтобы найти ярлык, который работает!
Свернуть в определения
CTRL + M, O
Развернуть все очертания
CTRL + M, X
Развернуть или свернуть все
CTRL + M, L
Это также работает с другими языками, такими как TypeScript и JavaScript
Как вы можете видеть, есть несколько способов добиться этого.
Я лично использую:
Развернуть все: CTRL + M + L
Свернуть все: CTRL + M + O
Bonus:
Развернуть/свернуть расположение курсора: CTRL + M + M
Visual Studio 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-
Изменить .CollapseCurrentRegion: CTRL + NUM-
Edit.ExpandAllOutlining: CTRL + SHIFT + NUM+
Edit.ExpandCurrentRegion: CTRL + NUM+
Вы можете использовать Ctrl + M и Ctrl + P
Он называется Edit.StopOutlining
Для коллапса вы можете попробовать CTRL + M + O
и развернуть с помощью CTRL + M + P
. Это работает в VS2008.
Перейдите в Инструменты- > Параметры- > Текстовый редактор- > С# → Дополнительно и снимите флажок в первом флажке. Вводите режим выделения при открытии файлов.
Это позволит решить эту проблему навсегда
Я всегда хотел, чтобы 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 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 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 "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