Is there a keyboard shortcut in Eclipse to fold the current method/block?

37,116

Solution 1

By default they're bound to Ctrl + Numpad_Minus and Ctrl + Numpad_Plus, but you can rebind them.

Solution 2

To expand on petrilli's answer:

  • Ctrl + Numpad_Multiply can also be used to expand all
  • Ctrl + Shift + Numpad_Divide is bound to collapse all
  • Ctrl + Numpad_Divide toggles folding on and off

And yes, they can all be rebound, if you know what text to filter on in Windows | Preferences | General | Keys.

"Folding", "Expand", "Collapse" are keywords that should get you all of the relevant commands.

Solution 3

If you are using eclipse-pydev then the default keybinds are

ctrl + 9 : collapse all one level

ctrl + 0 : expand all one level

ctrl + -_ : collapse current location

ctrl + =+ : expand current

Share:
37,116

Related videos on Youtube

dw.mackie
Author by

dw.mackie

I'm a software developer in Cary, NC, working in java, actionscript, and C. In my spare time, I like honing my skills in the art and craft of programming, plus brewing beer, cooking, and fixing (or attempting to fix) cars and motorcycles.

Updated on July 05, 2022

Comments

  • dw.mackie
    dw.mackie almost 2 years

    Hey, question says it all. I have folding turned on in Eclipse (v3.4), and rather than having to click the little +/- in the page gutter, I'm wondering if there's a keyboard shortcut to just "fold the current method". A quick look at the menus and what-not in eclipse doesn't show a menu item for it, so maybe you just can't do it.

    Anyone?

  • eon
    eon about 10 years
    Not on a Mac, apparently.
  • Roy Hinkley
    Roy Hinkley almost 10 years
    @petrilli What is Numpad_plus on macbook pro? I don't have a number keypad.
  • ToolmakerSteve
    ToolmakerSteve over 9 years
    NOTE: If you don't see the "-"s/"+"s on blocks, then "folding" is disabled. Rt-Click on the gutter (where you would normally see those "+"s), select "Folding > Enable Folding". (Here you will also see the keyboard shortcuts for the various folding actions.) Ctrl+Numpad_Divide is the shortcut to toggle enable folding on/off. This is annoying, because that is easy to do by accident instead of Ctrl+Shift+Numpad_Divide, which is what you often want to do when you open a file, to collapse everything, to see the overall structure.
  • StuckOnSimpleThings
    StuckOnSimpleThings almost 9 years
    So it appears that I had folding disabled. If anyone needs to enable folding under the version of Eclipse I was using it could be found under Window -> Preferences -> Java -> Editor -> Folding.
  • wisbucky
    wisbucky about 6 years
    Some laptops have a virtual numpad if you use the FN or NumLock key. I don't think macs have that, so you're better off just rebinding the keys to something else.