Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show(unfold) the hidden(folded) code in Intellij-IDEA with keyboard shortcut?

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

like image 666
tri Avatar asked Dec 05 '16 04:12

tri


People also ask

What is Ctrl Shift O in IntelliJ?

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.

How do you expand & collapse the code blocks IntelliJ?

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.

What does Ctrl Alt l do in IntelliJ?

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.


2 Answers

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.

like image 184
DimaSan Avatar answered Sep 18 '22 17:09

DimaSan


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

like image 42
Frederic Close Avatar answered Sep 17 '22 17:09

Frederic Close