Search code examples
phpstormcode-folding

Is there a way to collapse only methods and doc blocks on demand in PhpStorm?


I have seen this question but if I apply the Ctrl+Shift+- shortcut it collapses everything including class, method, doc, if/try-catch/foreach etc. Basically every block within curly braces are folded which makes it a p.i.t.a to view code. I want to reduce the visual clutter, so what I would like to see is only the method and doc blocks collapsed, so that I can quickly navigate to method and inspect code from thereon.


Solution

  • After spending some time with the IDE I figured it out for myself. One can do Ctrl+Shift+- and then Ctrl+Shift++. Basically the first shortcut action collapses everything and the second action expands everything but method definitions and doc blocks. If you apply Ctrl+Shift++ a second time then PhpStorm expands everything including methods and docs.

    This can be effected from the menu (without shortcuts) using mouse with the following steps:

    1. Menu -> Code -> Folding -> Expand all to level -> 5
    2. Menu -> Code -> Folding -> Expand all to level -> 1
    

    This does the reverse operation of the first method, i.e. first expands everything and then collapses just methods and docs, but the effect is the same.

    I use NetBeans keymap scheme, so things might be slightly different at your side, but the idea is the same.