In one place so I don't have to look it all up (and invariably get the wrong app's shortcuts first) when I forget again

Code folding for Visual Studio 2019 (the old lady):

The following commands can be found on theย Editย >ย Outliningย submenu.

TABLE 1
NameDescription
Hide Selection(Ctrl+M,ย Ctrl+H) - Collapses a selected block of code that would not normally be available for outlining, for example anย ifย block. To remove the custom region, useย Stop Hiding Currentย (orย Ctrl+M,ย Ctrl+U). Not available in Visual Basic.
Toggle Outlining Expansion(Ctrl+M,ย Ctrl+M) - Reverses the current hidden or expanded state of the innermost outlining section when the cursor lies in a nested collapsed section.
Toggle All Outlining(Ctrl+M,ย Ctrl+L) - Sets all regions to the same collapsed or expanded state. If some regions are expanded and some collapsed, then the collapsed regions are expanded.
Stop Outlining(Ctrl+M,ย Ctrl+P) - Removes all outlining information for the entire document.
Stop Hiding Current(Ctrl+M,ย Ctrl+U) - Removes the outlining information for the currently selected user-defined region. Not available in Visual Basic.
Collapse to Definitions(Ctrl+M,ย Ctrl+O) - Collapses the members of all types.
Collapse Block:<logical boundary>(C++) Collapses a region in the function containing the insertion point. For example, if the insertion point lies inside a loop, the loop is hidden.
Collapse All in: <logical structures>(C++) Collapses all the structures inside the function.

Code folding for Visual Studio Code (the upstart) from stackoverflow.com:

As of Visual Studio Code version 1.12.0, April 2017, seeย Basic Editing > Foldingย section in the docs.

The default keys are:

Fold All:ย CTRL+K,ย CTRL+0ย (zero)

Fold Level [n]:ย CTRL+K,ย CTRL+[n]*

Unfold All:ย CTRL+K,ย CTRL+J

Fold Region:ย CTRL+K,ย CTRL+[

Unfold Region:ย CTRL+K,ย CTRL+]

*Fold Level: to fold all but the most outer classes, tryย CTRL+K,ย CTRL+1

Macs: useย โŒ˜ย instead ofย CTRLย (thanks Prajeet)

Labels: , ,