572

Eclipse has that "+/-" on the left to expand and collapse blocks of code.

I've got tens of thousands of lines to go through and would really like to just collapse everything, and selectively expand blocks to look at them.

5
  • 1
    Check also this thread: stackoverflow.com/questions/3450880/… Commented Feb 26, 2013 at 10:06
  • 1
    How about collapsing just the code and not the comments? I guess I could generate a javadoc but still it would be nice Commented Nov 20, 2013 at 20:00
  • 1
    Eclipse has tons of options. Considering your purpose, Ctrl+O (ctrl and letter O) might be the most practical. It allows selecting and jumping to specific blocks. Commented Jul 15, 2015 at 12:03
  • If your keyboard doesn't have numpad, check akf's answer. Commented Feb 5, 2016 at 13:48
  • Key binding is different for Eclipse Neon on Linux. To check key binding for you version on eclipse on your OS, check under Preferences->General->Keys. or search for "keys" in Preferences. Then look for "Collapse All" and "Expand All" Commented Oct 23, 2016 at 15:57

17 Answers 17

893

There is a hotkey, mapped by default to Ctrl+Shift+NUM_KEYPAD_DIVIDE.

You can change it to something else via Window -> Preferences, search for "Keys", then for "Collapse All".

To open all code blocks the shortcut is Ctrl+Shift+NUM_KEYPAD_MULTIPLY.

In the Eclipse extension PyDev, close all code blocks is Ctrl + 9

To open all blocks, is Ctrl + 0

Sign up to request clarification or add additional context in comments.

20 Comments

You might be interested in the opposite shortcut 'expand all' as well.Ctrl + Shift + *
Is there a command for inverting collapsed/expanded state, so I can just press same key combination and it'd expand or collapse it depending on the current state of the code block? Thanks!
Just a note, it seems like this shortcut (no matter what you bind it to) doesn't work for PyDev. If someone reads this and knows the opposite to be true, please post otherwise!
I just wanted to say that another way is to right-click the narrow vertical bar has has all of the (+)/(-) little pluses and minuses. The option to fold the code will be there.
@seafangs PyDev has its own bindings for this stuff. Collapse all is ctrl+9 by default. See here: pydev.org/manual_adv_keybindings.html
|
151

In addition to the hotkey, if you right click in the gutter where you see the +/-, there is a context menu item 'Folding.' Opening the submenu associated with this, you can see a 'Collapse All' item. this will also do what you wish.

5 Comments

Use fn and divide that is being called when fn button is pressed
Nice one - there is also the possibility to collapse comments only!
Ctrl + Shift + * wasn't working on my Eclipse Java EE Indigo; thank you
In eclipse 3.8 with PyDev 4.1 the gutter has no 'Folding' option in the context menu
You can actually click anywhere in the left hand gutter (breakpoints, line numbers, +/-). This makes it easier than trying to aim for a tiny +/-
29

A "Collapse All" command exists in recent builds (e.g. 3.2 M6) and is bound to Ctrl+Shift+NUM_KEYPAD_DIVIDE by default.

You can also configure it in Preferences->Editor->Keys.

2 Comments

Could you please tell me for mac ?
@KumaresanPerumal Instead of Ctrl, the button is Command, so: Command + Shift + NUM_KEYPAD_DIVIDE on Mac. Tested myself just now. See also: stackoverflow.com/questions/9340049/…
12

If you always want the code collapsed by default, go to Windows > Preferences. Search for "folding". Then check all the items under "Initially fold these elements".

enter image description here

1 Comment

Thanks for this. Folding was disabled by default for me.
11

The question is a bit old, but let me add a different approach. In addition to the above hot-key approaches, there are default preference settings that can be toggled.

As of Eclipse Galileo (and definitely in my Eclipse Version: Indigo Service Release 2 Build id: 20120216-1857) language specific preferences can open up new files to edit which are already collapsed or expanded.

Here is a link to Eclipse Galileo online docs showing the feature for C/C++: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/reference/cdt_u_c_editor_folding.htm .

In my Eclipse Indigo I can open the Folding Preferences window via : menu/ Window/ Preferences/ Java/ Editor/ Folding and set all options on so I can open files by default that are completely collapsed.

Comments

9

Right click on the +/- sign and click collapse all or expand all.

1 Comment

Which does not work for the PyDev extension, as of 4.1
8

Ctrl+Shift+/ and Ctrl+Shift+* works great for Aptana Studio 3.

Apart from that you can always use Window > Preferences > Editors > Foldings to enable it

Comments

6

Just to sum up:

  1. anycode:
    • ctrl + shift + NUMPAD_divide = collapse all
    • NUMPAD_multiply = exand all
  2. pydev:
    • -ctrl + 0 = collapse all
    • -ctrl + 9 = exand all

Comments

4

Right click on the circles +/- sign and under Foldings select Collapse All

Comments

4

If you are using PyDev in Eclipse, its Ctrl0 and Ctrl9 for collapse all and uncollapse all respectively. Ctrl- and Ctrl= to collapse individual methods when your cursor is on the line of the method declaration.

1 Comment

In PyDev, <kbd>Ctrl</kbd>+<kbd>9</kbd> collapses and <kbd>Ctrl</kbd>+<kbd>0</kbd> uncollapses all code blocks. A list of common PyDev shortcuts can be found at pydev's website.
3

I had the same problem and found out Folding can be enabled or disabled, and in my case got disabled somehow.

To solve it, simply right click on the line numbers/breakpoint section (vertical bar in the left of the editor), then under the 'Folding' section chose 'Enable folding'.

ctrlshift/ should be working fine after.

Comments

1

Shortcuts that worked for me in Versions Oxygen.2 Release (PHP/WINDOWS 7) were

  1. Collapse all code blocks: CTRL + SHIFT + NUMPAD_DIVIDE
  2. Expand all code blocks : CTRL + NUMPAD_MULTIPLY

Comments

1

I noticed few things:

Ctrl+/ toggles Folding-enabled or -disabled.

It is Ctrl+* that expands. Ctrl+Shift+* collapses just like Ctrl+Shift+/

Comments

0

In case you don't have a separate numpad, you can activate the overlapping numpad using the number lock- this varies with the type of keypad-> fn + numlk for hp

then try ctrl + shift + numpad_Divide

should work fine

Comments

0

Collapse all : CTRL + SHIFT + /

Expand all code blocks : CTRL + *

Comments

0

i was using lapop numpad was orange color which will get enable using function (Fn) button ...so try

shift + crtl + fn + (see where is divide) in my case its on 0

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

Keys are not working for me but there is pane where row nos are written, RC -> Folding-> Collapse and Expand option is present you can use them.

let me know if you find this answer interesting :-) Happy learning.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.