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?
In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.
To collapse or expand all code fragments, press Ctrl+Shift+NumPad - / Ctrl+Shift+NumPad + . IntelliJ IDEA collapses or expands all fragments within the selection, or, if nothing is selected, all fragments in the current file, for example, all methods in a file.
Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.
In IntelliJ IDEA you can use to following shortcuts to fold/unfold code blocks:
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):
And even after that your folding/unfolding hotkeys listed above will work as well.
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 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With