Udostępnij za pośrednictwem


Did you know... how to collapse and expand code? - #035

Yesterday’s tip talked about how to cut a collapsed block of code, but how do you collapse a block of code anyways?

There are basically five commands for "outline toggling," which can be found on the Edit – Outlining menu.

#1 – Toggle Outlining Expansion

Toggle Outlining Expansion menu item

By Pressing Ctrl+M, Ctrl+M anywhere within the code block, you can toggle between expanding and collapsing the given block of code.

Toggle Outlining Expansion Example

#2 - Toggle All Outlining

Toggle All Outlining menu item

By Pressing Ctrl+M, Ctrl+L anywhere in the editor, you can toggle between expanding and collapsing the entire file.  When completely collapsed, you can then drill down into the section of code you are most interested in.  When completely expanded, you can view all code without having to expand any sections.

Toggle All Outlining Example

#3 – Stop Outlining

Stop Outlining menu item

By Pressing Ctrl+M, Ctrl+P anywhere in the editor, you can turn off outlining.

Stop Outlining Example

#4 – Start Outlining

StartAutomaticOutlining

Unfortunately, start and stop outlining are not the same command, so you can’t toggle between one state and the other.  Additionally, using the general development settings, start is not bound to a keyboard shortcut.  So, you will need to go to Edit – Outlining – Start Automatic Outlining to turn on outlining again.

StartAutomaticOutliningExample

#5 – Collapse to Definitions

Collapse To Defintions

In my opinion, this is the most useful command of all outlining (mostly because it was the only one I used… except for when I had to test the others).  This allows you to quickly glance at all of your functions.

Collapse To Defintions Example

Lastly, if these keyboard shortcuts don’t match what you have, it is because you are using a different set of default settings that you chose on your first launch of Visual Studio.  I’m using the General Development Settings for all these tips.

Technorati tags: VS2005Tip, VS2008Tip

Comments

  • Anonymous
    October 08, 2007
    For some time I have been subscribing to Sara Ford's blog where she shares useful tips for Visual

  • Anonymous
    January 14, 2008
    Yesterday's tip was everything you ever wanted to know about outlining in the editor. Today, we'll explore

  • Anonymous
    July 06, 2008
    The comment has been removed

  • Anonymous
    July 06, 2008
    この記事を 3:00 AM PST に公開するつもりだったのに、3:00 PM PST に設定していました。遅くなって申し訳ありません。 昨日のワンポイント では、折りたたまれたコード ブロックを切り取る方法をご紹介しました。では、コード

  • Anonymous
    September 11, 2008
    Вчерашний совет рассказывал о том, как вырезать свернутый сегмент кода, но как его свернуть? На самом