简体   繁体   中英

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?

IntelliJ IDEA 中的隐藏代码

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 (eg, 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 -

在此处输入图片说明

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. 在此处输入图片说明

  • Then Ctrl + -

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM