56

In Visual Studio C# (2008), Ctrl+M+L expand all the regions.

There's also a setting in menu:

Tools -> Options -> Text Editor -> C# -> Advanced

to not collapse during file open. I see no equivalents in VB.NET.

Is there a way to expand all the regions, not just the one which has focus in VB.NET?

Or a macro or add-in that does it? I just hate not being able to see all the code.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
  • I reset the settings and it's still not working. It works in C# but not vb.net. The only thing working in vb.net is collapsing/expanding the region the cusrosr is on via ctril-M-M. I have read posts on the web about others having the same issue like this one although it pertains to VS 2005. [http://www.eggheadcafe.com/forumarchives/NETVisualBasic/Oct2005/post24342618.asp](http://www.eggheadcafe.com/forumarchives/NETVisualBasic/Oct2005/post24342618.asp) This solution worked for me which involves using a Macro. (If someone created a macro, then the problem is real. I am sure region functionality – Tony_Henrich Jul 09 '09 at 19:24
  • This: https://marketplace.visualstudio.com/items?itemName=Shanewho.IHateRegions#overview – CAD bloke Nov 23 '17 at 22:43
  • This: https://github.com/fsdsabel/ExpandRegions/releases (others extensions are abandoned/did not seem to work in 2019) – David Oct 07 '20 at 12:39

8 Answers8

28

In Visual Studio 2012 and 2013 there is an option for deactivating collapsing (called 'outlining mode').

You can find it under:

Text-Editor->Basic->VB Specific

and then uncheck "Enable outlining mode".

But you will then lose the feature for collapse/expand at all.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Sebastian
  • 2,874
  • 25
  • 31
  • 39
    For C# developers this can be found under `Text Editor` -> `C#` -> `Advanced` -> `Enter outlining mode when files open`. Uncheck this option and regions will be disabled. – Jan_V Feb 19 '15 at 13:20
  • 9
    Unfortunately you can't seem to use 'outlining mode' _without_ having it all collapsed by default. – Nyerguds May 12 '15 at 07:19
10

If you are willing to remove regions you can try this:

Ctrl+F

  • Quick Replace
  • Find Options
  • Use: Regular Expressions

Find What:

^\s*#(end)?region.*$

Replace with:

[leave replace box empty]

Explanation:

  • ^ - Match the start of a line
  • \s* - Match zero or more whitespace characters
  • # - Match one # character
  • (end)? - Optionally match the string end
  • region - Match the string region
  • .* - Match zero or more of any other characters
  • $ - Match the end of the line

This will effectively find all #region or #endregion lines, whether they are indented or not, and whether they have description text after them or not.

Herohtar
  • 5,347
  • 4
  • 31
  • 41
7

In the Edit Menu, the Outlining submenu, you have all the options. Including Toggle All Outlining (Ctrl+M+L by default).

Maybe your key mappings were altered.

If you so desire, you can even select menu:

Edit -> Outlining -> Stop Outlining
J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
jvanderh
  • 2,925
  • 4
  • 24
  • 28
  • The corresponding commands to change the shortcuts are `Edit.ToggleAllOutlining` and `Edit.StopOutlining` – bugybunny Nov 28 '18 at 08:26
3

In VB.Net, do a Search and Replace and select Use Hidden and Use Regex:

Replace:

^.*\#(end)*(:Wh)*region.*\n

With:

John Cruz
  • 1,562
  • 4
  • 14
  • 32
2

I wrote an extension to do this (and more), and it works for VB and C#. See this answer for more info:

Hiding the regions in Visual Studio

Community
  • 1
  • 1
NotDan
  • 31,709
  • 36
  • 116
  • 156
1

That's pretty odd. The default profile settings for VB.Net and C# should bind the outlining functions to Ctrl+M, Ctrl+L combos.

It's possible that your profile is in a weird state. Try resetting your profile to VB.Net settings and see if that fixes the problem.

ToolsImport / Export SettingsReset All SettingsVB.Net Profile

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
1

Once I changed:

#Region Form Level Events
#End Region

To (note the addition of quotes):

#Region "Form Level Events"
#End Region

The minus signed appeared and I was able to collapse/expand Regions.

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
-3

I came up with this trick:

Ctrl+F

  • Quick Replace
  • Find:

#Region

  • Search in: current document (or entire project or wherever you need to expand regions)
  • Search in hidden text

Then press Return and keep it pressed until VS notify the search is endend. As a result all your '#region's have been expanded in very few seconds.

Fil
  • 1,032
  • 13
  • 29