Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Expand/collapose in .cshtml file in Visual Studio 2017?

I am using Visual Studio 2017. I can expand and collapse in .cs files using command as follows:

Expand CTRL+M+L
Collapse CTRL+M+O

But same is not working in .cshtml file? Is there any workaround?

like image 914
Ravi Anand Avatar asked Oct 23 '25 16:10

Ravi Anand


2 Answers

Ctrl+M+A collapses all, Ctrl+M+X expands all in my installation. You can see them by opening Tools > Options..., select Keyboard under Environment. In the Show commands containing, find Edit.CollapseAllOutlining (you can search too) and Edit.ExpandAllOutlining. You should be able to see the existing binding or add your own (make sure to select Text Editor or Global).

Keyboard binding options

like image 110
Heretic Monkey Avatar answered Oct 26 '25 14:10

Heretic Monkey


From what I could determine, Visual Studio doesn't support expanding and collapsing for this file type.

There is a sort of workaround, although it has its limitations. You can manually select regions in a given file that you'd like to hide and press Ctrl+MCtrl+H (also found in the Edit->Outlining menu) to hide them. Visual Studio will "remember" that you want these specific regions to be hideable, and you can now show and hide these sections with the outlining commands (for example Ctrl+MCtrl+A will hide all sections, and Ctrl+MCtrl+X will show all sections, depending on your keybindings).

This isn't a perfect solution by any means, because you need to set up the regions manually. But it might come in handy in some cases.

Here's an example of a .cshtml file after I set up the regions:

expanded

...and after pressing Ctrl+M+L once:

collapsed

like image 29
Kevin Meboe Avatar answered Oct 26 '25 15:10

Kevin Meboe