Collapse or Expand Code using shortcut key in Visual Studio 2022
In this Visual Studio tip, let’s learn what is Outlining and how to expand and collapse the section of code in Microsoft Visual Studio 2022.
In Visual Studio, you can have the text regions defined which you may expand and collapse anytime. You can define your own outlining region as well.
For example, assume that you have the region or section of code that you are working on. This section or region is usually highlighted with – and + symbol as shown in the screenshot below. To collapse the section, you click on the – symbol and to expand, you click on the + symbol.
If you need to collapse or expand the section, you can also manually navigate to Edit -> Outline in Visual Studio editor and then select “Toggle Outlining Expansion” or “Toggle All Outlining”
Alternately, you can use the shortcut key “Ctrl + M, Ctrl + M” for toggling the outlining expansion or “Ctrl + M, Ctrl + L” for toggling all outlining.
How to Stop the Outlining in Visual Studio?
You can remove all the outlining information for the entire document that you are working on. To remove the outlining, you can use the shortcut key “Ctrl + M, Ctrl + P). You can alternatively select Edit-> Outlining-> Stop Outlining as well.
When the Outlining is stopped on the current document in Visual Studio, you’ll not see the + and – symbols or outlines to expand/collapse the section.
To add the outlining back to the current document in the Visual Studio editor, navigate to Edit -> Outlining and then click “Start Automatic Outlining”