Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VisualStudio 2019 - expand all regions below and including

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 ?

like image 613
kofifus Avatar asked Oct 12 '25 15:10

kofifus


2 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:

  1. Get the cursor location.
  2. Store the 'start' and 'end' line numbers
  3. 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.

like image 174
itsho Avatar answered Oct 14 '25 10:10

itsho


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.

like image 33
Dan Avatar answered Oct 14 '25 10:10

Dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!