matteskolin


Visual Studio Tips

Visual Studio – Collapse and Expand Shortcuts – What they actually do

Posted by matteskolin on

Visual Studio has several shortcuts available for expanding and collapsing sections of code. These Shortcuts have been tested with Visual Studio 2017 15.87 with default settings. Below I explain what each of these does in more detail.

Collapse All Outlining (Edit.CollapseAllOutlining)
Ctrl+ (M, A)

Toggle All Outlining (Edit.ToggleAllOutlining)
Ctrl+ (M, L)

Toggle Outline Expansion (Edit.ToggleOutlinineExpansion)
Ctrl+ (M,M)

Expand All Outlining (Edit.ExpandAllOutlining)
Ctrl+ (M,X)

Expand Current Region (Edit.ExpandCurrentRegion)
Ctrl+(M,E)

Collapse Current Region (Edit.CollapseCurrentRegion)
Ctrl+(M,S)

Toggle Outline Expansion
Ctrl+ (M,M) – This is probably the shortcut that makes the most sense of this bunch. Pressing this command repeatedly will open and close the region or auto-outlined section under the cursor. 

In the example below this can be used to open and close the constructors region, as well as the Foo and Bar2 types separately.

Collapse All Outlining
Ctrl+ (M, A) In the code below, this command does what you would expect. All outlining is collapsed as much as possible. 

Expand All Outlining
Ctrl+ (M,X) – this command works great for expanding everything so all code is visible

Toggle All Outlining
Ctrl+ (M,L)  this command behaves someone strangely. The word toggle suggests that repeating this command will switch outlining back and forth. This isn’t quite what happens. The first time you press Ctrl+ (M,L) if there is a mixture of open and closed sections in the file, the closed sections will be opened as the first step in the toggle. 

In the example below, if the Constructors region starts closed, typing this command will first open the region, and the command must be executed a second time to actually toggle all outlining. This is relatively unintuitive. 


Expand Current Region and Collapse Current Region
Ctrl + (M,E) – Expand
Ctrl + (M,S) – Collapse

These commands will collapse or expand the region under the cursor. While editing code I have a hard time thinking of time where one of these commands would be preferable to “Toggle Outline Expansion” above. 

The associated commands may be useful outside of an editing context, such as in auto generated code, code assistance extensions, etc.


Below is simple file to demonstrate the outlining system…

namespace ExpandCollapse
{


    public class Foo
    {
        public int Integer1 { get; set; }

        #region Constructors 
        public Foo()
        {

        }
        #endregion

    }

    public class Bar2
    {

        public Bar2()
        {
            Console.WriteLine("Hello from Bar2");
        }

        public int Int1 { get; set; }
    }

    public class Food
    {

    }
}

Visual Studio Tips

Strange Symbols in the Indicator Margin

Posted by matteskolin on

Update 12/16/2018
-It appears after further experimentation that these symbols may not be generated from ReSharper… I will continue to pay attention and see if we can figure out exactly what these are doing…

I noticed some strange symbols appearing  in Visual Studio 2017 recently.

They constantly change as type, and seem to have something to do with line breaks or spaces.  They appear to be generated by ReSharper, as they disappeared when I disabled the extension. I have posted to to ReSharper Community here seeking documentation.

 Post on ReSharper Community Site

This area to the left of the line numbers in the left-side bar is called the “Indicator Margin”. Is used for other things such as breakpoints and bookmarks. 

https://resharper-support.jetbrains.com/hc/en-us/community/posts/360001804679-What-are-these-Indicator-Margin-symbols-

rned is called the “Indicator Margin” in Visual Studio 2017. This is the left-hand side bar that appears