570

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.

Quonux
  • 2,975
  • 1
  • 24
  • 32
ambertch
  • 7,581
  • 4
  • 28
  • 40
  • 1
    Check also this thread: http://stackoverflow.com/questions/3450880/how-to-collapse-blocks-of-code-in-eclipse – Igor Gorjanc Feb 26 '13 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 – Clarence Liu Nov 20 '13 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. – Marquez Jul 15 '15 at 12:03
  • If your keyboard doesn't have numpad, check [akf's answer](http://stackoverflow.com/a/1726549/606662). – Markus Pscheidt Feb 05 '16 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" – katta Oct 23 '16 at 15:57

16 Answers16

888

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

a1an
  • 3,526
  • 5
  • 37
  • 57
ChssPly76
  • 99,456
  • 24
  • 206
  • 195
  • 63
    You might be interested in the opposite shortcut 'expand all' as well.Ctrl + Shift + * – banterCZ May 21 '12 at 06:41
  • 2
    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! – Art Jul 19 '12 at 06:33
  • 2
    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! – floer32 Aug 23 '12 at 18:04
  • I found it insanely unreasonable that the developers of Eclipse didn't implement this into the Menu. – lamwaiman1988 Feb 27 '13 at 07:48
  • 16
    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. – Anonsage Mar 19 '13 at 16:18
  • 5
    @seafangs PyDev has its own bindings for this stuff. Collapse all is ctrl+9 by default. See here: http://pydev.org/manual_adv_keybindings.html – Cam Jackson May 27 '13 at 13:32
  • Hi @ChssPly76, Can you create Headers in Eclipse? Like in Xcode where you can easily navigate through your code by clicking the pragma mark? – KarenAnne Aug 23 '13 at 06:27
  • 1
    Expanding code blocks in Zend Eclipse PDT is set to `Ctrl`+`*` by default. Note: There's no `Shift` involved. – Randell Nov 07 '13 at 22:53
  • Just in case anyone is using OS X, it is Cmd + Shift + / for Collapse All; and, Cmd + Shift + * for Expand All :) Pretty obvious, but just making sure :) – Brandon Apr 19 '14 at 09:39
  • Is there a way to hide these blocks? I want to see just the current block, nothing else more. And then, pressing F3 on other methods, I want to go to method "unhide" it. I know that is too much, but I like to see clearly in what I am working. – robsonrosa Aug 05 '15 at 12:32
  • Hint: the command that gets invoked is `Toggle Folding`. (if you don't have a number keypad because you're using a Macbook then add the binding as just `Shift + Cmd +5`) – Sridhar Sarnobat Apr 05 '16 at 18:11
  • 1
    In Eclispe Neon with PyDev, it is now CTRL + numpad divide – adrienlucca.net Oct 18 '16 at 19:48
  • 1
    Ctrl+Shift+NUM_KEYPAD_MULTIPLY. not working on eclipse neon IDE. Instead of that Ctrl+NUM_KEYPAD_MULTIPLY. worked fine to open all brackets – Hashan Nov 10 '16 at 09:18
  • In Aptana studio which uses Eclipse extension, works only with the first solution to Collapse with (Ctrl+Shift+NUM_KEYPAD_DIVIDE). Does not work with other options to open the Collapsed items. – Raj Aug 05 '17 at 10:07
  • If these shortcuts don't work for you, it could be because you have folding disabled. To enable folding, the shortcut is `Ctrl`+`Numpad_Divide` – Jake Reece Oct 22 '18 at 14:05
  • while working on a laptop .. its good to change this key to something else .. or use context menu as per akf's answer below https://stackoverflow.com/a/1726549/3509609. – Vikash Feb 28 '19 at 04:38
  • If it didn't work, closing the current file tab then reopening it could solve the problem. – Accountant م Jan 02 '20 at 01:17
  • Ctrl++NUM\_KEYPAD\_MULTIPLY alone if you really want to expand all, imports included. (With the shift key it doesn't expand import which is exactly want I was looking for). – pdem Jul 01 '21 at 09:34
  • this not working in my version Version: 2022-03 (4.23.0) – Pankaj K. Feb 09 '23 at 05:46
150

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.

akf
  • 38,619
  • 8
  • 86
  • 96
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.

earthmover
  • 4,395
  • 10
  • 43
  • 74
Mark Mayo
  • 12,230
  • 12
  • 54
  • 85
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.

donfede
  • 734
  • 1
  • 9
  • 25
10

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

wisbucky
  • 33,218
  • 10
  • 150
  • 101
9

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

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
NightSkyCode
  • 1,141
  • 2
  • 16
  • 33
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

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
Hittz
  • 688
  • 6
  • 7
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
bummi
  • 27,123
  • 14
  • 62
  • 101
partizanos
  • 1,064
  • 12
  • 22
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.

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
lightalchemist
  • 10,031
  • 4
  • 47
  • 55
  • 1
    In PyDev, Ctrl+9 collapses and Ctrl+0 uncollapses all code blocks. A list of common PyDev shortcuts can be found [at pydev's website](http://pydev.org/manual_adv_keybindings.html). – Cody Piersall Nov 30 '12 at 05:09
4

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

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.

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
David Neto
  • 809
  • 1
  • 12
  • 20
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
1

I noticed few things:

Ctrl+/ toggles Folding-enabled or -disabled.

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

Alwaysa Learner
  • 496
  • 3
  • 11
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

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
av003
  • 1
0

Collapse all : CTRL + SHIFT + /

Expand all code blocks : CTRL + *

Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
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

  • 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](/help/how-to-answer). – Community Jul 26 '22 at 16:29