Share via


Outlining and Hiding Code

Visual Studio .NET Code Editor offers you the option of creating a hierarchical, outlined overview that gives you an overall view of the structure of your document.

Outlining code

You can select a region of code (that is, a selected block of text) and hide (collapse) it so that it appears under a symbol. You can then expand or hide the region by clicking the plus sign (+) next to the symbol. Outlined code is not deleted, it is merely hidden from view.

You can create nested regions of outlining so that you might expand one section that contain one or more subsections of collapsed text.

After the text is outlined and collapsed, it appears as:

After outlining code, you can expand only the sections you want to work on, collapse them when you are done, and then move to another section. When you are through outlining, you can use the Stop Outlining command to remove the outline information without disturbing your underlying code.

Caution   Outlining information in a region is lost if you make changes to that region, such as deleting horizontal white space or using a find and replace operation.

In the Outlining submenu of the Edit menu and in the context menu, the following commands are available for all languages:

  • Hide Selection — Hides the currently selected text. Text must be selected to execute this command. Shortcut keys are CTRL+M and then CTRL+H. (This command is available in Visual C# .NET only when auto-outlining is turned off or Stop Outlining is selected.)
  • Toggle Outlining Expansion — Reverses the current hidden or expanded state of the innermost outlining section in which the cursor lies when you are in a nested collapsed section. Shortcut keys are CTRL+M and then CTRL+M.
  • Toggle All Outlining — Sets all procedures to the same hidden or expanded state. If some regions are expanded and some hidden, then the hidden regions are expanded. Shortcut keys are CTRL+M and then CTRL+L.
  • **Stop Outlining **— Removes all outlining information for the entire document. All procedures are visible and the symbols removed, but the underlying code is undisturbed. Shortcut keys are CTRL+M and then CTRL+P.
  • Stop Hiding Current — Removes the outlining information for the currently selected user-defined region. Shortcut keys are CTRL+M and then CTRL+U. (This command is available in Visual C# .NET only when auto-outlining is turned off or Stop Outlining is selected.)
  • Collapse to Definitions — Collapses the members of all types so that all of the members belonging to a type are clearly seen. Identical to the Collapse Block command except that the environment automatically runs through all of the code in the document, creates regions in each of your procedures, and then hides them. Shortcut keys are CTRL+M and then CTRL+O.

If your project is a Visual C++ .NET project, and the insertion point is within a block, two additional commands are available:

  • Collapse Block — The environment uses the programming language's service to automatically determine logical boundaries for creating a region in the function containing the insertion point, and then hides it. For example, if the insertion point lies inside a loop, a region is created for that statement and the region is hidden. Each time you execute this command, the next higher-level containing statement is collapsed until you end up at the top of a procedure or other top-level definition in your code.
  • Collapse All In — The same as Collapse Block, only it recursively collapses all logical structures inside the function in a single step.

To create and hide a region

  1. Select the text you want to hide.

  2. On the Edit menu, choose Outlining, and then choose Hide Selection, or choose the command from the context menu.

    You can repeat this process several times and then use the Toggle Outlining Expansion or Toggle All Outlining command to hide them or to make them visible.

To collapse code within a single statement block

  1. If your project is Visual C++ .NET, put the cursor inside the area you want to hide, such as within a loop or elsewhere within a procedure.

  2. In the Outlining command of the Edit menu, choose Collapse Block.

  3. To collapse all logical structures within a function, choose Collapse All In.

    After doing this, you can choose either the Toggle Outlining Expansion or Toggle All Outlining command to display or hide the code.

To collapse all definitions in a document

  • On the Edit menu, choose Outlining, and then choose Collapse to Definitions.

    After doing this, you can use the Toggle Outlining Expansion or Toggle All Outlining command to hide them or to make them visible.

To stop outlining a specific outlined section of text

  • On the Edit menu, choose Outlining, and then choose Stop Hiding Current.

    This removes the user-defined region but does not disturb the text.

To stop outlining in an entire module

  • On the Edit menu, choose Outlining, and then choose Stop Outlining.

    All outlining information is discarded.

Expanding and collapsing regions

To expand or collapse a previously created region

  1. Put the insertion point (click the mouse) in the hidden region.
  2. On the Edit menu, choose Outlining, and then choose Toggle Outlining Expansion, or press CTRL+M twice, or choose the command from the context menu.
  3. Alternatively, you can click the plus sign (+) to the left of the region.
  4. Another way to expand or collapse a previously created region is to double-click the symbol.

The Undo and Redo commands on the Edit menu affect these actions. In other words, if you create a hidden region, choosing Undo reverses that action. Also, Cut, Paste and Drag-Drop operations retain the hidden regions and the outline information.

Script-only view

In the HTML Editor, you can activate a Script-Only view in which only script blocks are displayed.

To enable script-only view

  1. Open the HTML document.
  2. In the upper right corner of the document, choose the Script Only View button .
  3. To return to the default view, choose the Full HTML View button .

See Also

Editing Code, HTML, and Text