Is there a command/macro/keyboard shortcut that will expand the region where the cursor is and expand all collapsed regions inside it (recursively) ? if not can that be achieved ?
3 Answers
Short answer
As far as I know - No. There isn't a single shortcut that does that.
How to implement it by yourself
It's quite easy to create a plugin for Visual Studio that does exactly that:
- Get the cursor location.
- Store the 'start' and 'end' line numbers
- For each line:
- If it contains a region - expand it.
Few examples to begin with:
- https://github.com/LeonalaDiantes/RegionsWasher
- https://github.com/dnperfors/RegionExpander
- https://github.com/fsdsabel/ExpandRegions
- https://github.com/pauljmelia/regionsareevil
- https://github.com/yasam100/CodeRegionsSnippets-VSExtension
Some of the projects are very close to the thing you have in mind, so you might even fork it and do your changes.
:-)
Another option
you might get the same result by using Macros for Visual Studio Editor/Recorder:
And then, write a macro like this one or maybe even record the steps you like to "run".
IMO, with recording and playing it will be a little harder to achieve. but I'll be happy to be proved wrong.

- 4,640
- 3
- 46
- 68
I had the same problem, the following worked for me without having to make a macro or a plugin. Note, this is only a partial solution to the problem. I got it to expand recursively underneath a function, but I'm not sure how to reverse it (i.e. recursively collapse everything under the function again). To recursively collapse everything again, I could only figure to use (Ctrl+M, Ctrl+L), which collapses/expands everything in your file, but then you have to drill back down to the function you want.
Firstly, I got everything in a collapsed state by pressing (Ctrl+M, Ctrl+L). You may have to use that combination twice to get everything to collapse. Then I expanded a class and drilled down to the function I wanted to work on.
With the function in its collapsed state, I highlighted the single collapsed row it was on and pressed (Ctrl+M, Ctrl+M).
Doing so recursively expanded everything under the function.
I hope this partial solution helps someone who doesn't want to make a macro or plugin.
I believe ctrl + k
followed by ctrl+]
should unfold all subregions
replacing the ]
with [
should fold all subregions.

- 1,656
- 3
- 15
- 23