JetBrains / IntelliJ keyboard shortcut to collapse all methods

Intellij IdeaIdePhpstormKeyboard Shortcuts

Intellij Idea Problem Overview


I'm working on some legacy code that has a class that is 10,000+ lines of code and has 100s of methods. Is there a shortcut for any JetBrains IDE (since the shortcut would likely be shared across all of them) to collapse all the methods / functions so that only the method signatures are shown?

Something like this:

public String myMethod(String arg1, int arg2){...}

public String mySecondMethod(String arg1, int arg2){...}

Intellij Idea Solutions


Solution 1 - Intellij Idea

You may take a look at intellij code folding shortcuts.

For Windows/Linux do: Ctrl+Shift+-

For mac use Command+Shift+-

To unfold again do Ctrl+Shift++ or Command+Shift++ respectivley.

Solution 2 - Intellij Idea

The above suggestion of Ctrl+Shift+- code folds all code blocks recursively. I only wanted to fold the methods for my classes.

Code > Folding > Expand all to level > 1

I managed to achieve this by using the menu option Code > Folding > Expand all to level > 1.

I re-assigned it to Ctrl+NumPad-1 which gives me a quick way to collapse my classes down to their methods.

This works at the 'block level' of the file and assumes that you have classes defined at the top level of your file, which works for code such as PHP but not for JavaScript (nested closures etc.)

Solution 3 - Intellij Idea

go to menu option Code > Folding to access all code folding related options and their shortcuts.

Solution 4 - Intellij Idea

@precastic's answer above is, imo, the right idea.

Worth noting that in IDEA 2018.2 (and surely other nearby versions) there are default keyboard shortcuts for this: (showing Mac, see Code > Folding > Expand All to Level for your system):

Cmd+Option+Keypad *, 1 - expand all to level 1
Cmd+Option+Keypad *, 2 - expand all to level 2
...
Cmd+Option+Keypad *, 5 - expand all to level 5

Note: these are "second stroke" shortcuts. First press Cmd+Option+*, then release, then hit the number you want.

Solution 5 - Intellij Idea

You Can Go To setting > editor > general > code folding and check "show code folding outline" .

Solution 6 - Intellij Idea

In Rider, this would be Ctrl +Shift+Keypad *, 2

But!, you cannot use the number 2 on keypad, only number 2 on the top row of the keyboard would work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBradView Question on Stackoverflow
Solution 1 - Intellij IdealifusView Answer on Stackoverflow
Solution 2 - Intellij IdeaPrecasticView Answer on Stackoverflow
Solution 3 - Intellij IdeaRahul TiwariView Answer on Stackoverflow
Solution 4 - Intellij IdeaoverthinkView Answer on Stackoverflow
Solution 5 - Intellij IdeaMeysam JafariView Answer on Stackoverflow
Solution 6 - Intellij IdeaRosdi KasimView Answer on Stackoverflow