25

How can I show(unfold) the hidden(folded) code in IntelliJ IDEA, as shown in the picture below, just using keyboard without touching the mouse?

hidden code in intelliJ IDEA

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
tri
  • 361
  • 3
  • 6

4 Answers4

33

In IntelliJ IDEA you can use to following shortcuts to fold/unfold code blocks:

  • To fold and unfold CURRENT selected block of code:
    • CTRL+- and CTRL++ on Windows;
    • ⌘ CMD+- and ⌘ CMD++ on Mac;
  • To fold and unfold ALL blocks of code:
    • CTRL+⇧ SHIFT+- and CTRL+⇧ SHIFT++ on Windows
    • ⌘ CMD+⇧ SHIFT+- and ⌘ CMD+⇧ SHIFT++ on Mac.

By the way, in Settings → Editor → General → Code Folding you can specify the default folding behavior for a various situations (e.g., imports, one-line methods, inner classes, @SuppressWarnings annotations, array literals, generic constructors and many others):

enter image description here

And even after that your folding/unfolding hotkeys listed above will work as well.

DimaSan
  • 12,264
  • 11
  • 65
  • 75
5

To be sure which shortcuts are available go to settings > Keymap

then go to

Main Menu > Code > Folding

Expand default on mac : cmd+ default on win : ctrl + numpad + Collapse default on mac : cmd- default on mac : cmd- default on win : ctrl + numpad -

enter image description here

Frederic Close
  • 9,389
  • 6
  • 56
  • 67
3

The only available option for your need (about import statements) is,

  • Move your pointer to (+) button on the left hand side of the statement so you can see the pointer changes to hand mark. enter image description here

  • Then Ctrl + -

Find this for more info expanding/collapsing code. But this is more about blocks.

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
0

Easy to remember steps:

  • Press SHIFT twice
  • Type folding
  • Select Folding action
  • All options related to Expand and Collapse should be visible now (with keymaps)
Saikat
  • 14,222
  • 20
  • 104
  • 125