Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Eclipse Folding

DZone's Guide to

Eclipse Folding

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

No, this is not about how to fold Eclipse: it is about the Folding feature of the Eclipse editor view. My source files tend to get much larger than a single screen page. The Eclipse framework comes with many great editor and navigation features, but it would be great to have the amount of information reduced. Well, it can look like this:

Source file with source folding

Source file with source folding

Yes, this shows about 140 lines of code in a condensed way :-) . It gives me the high level picture. I can dive into the details on demand. What I’m using here is the Eclipse feature of Folding. Note the small + and - signs on the left side of the view: this is used to fold/unfold regions in the editor.

Toggle Folding

To toggle folding, I use the Ctrl+Numpad_Divide command. I can use the command as well with Ctrl+3 (see The Mother of all Eclipse Shortcuts):

Folding Commands

Folding Commands

Note: In case Numpad_Divide is not easily accessible on my keyboard layout, the key bindings can be changed under the menu Window > Preferences > General > Keys.

Enabling Folding

‘Toggle Folding’ just enables folding for the current editor view. By default it is not enabled when I open a new editor view. I can change and configure this. I go to the menu Window > Preferences and go the ‘Folding’ setting page as below: here I can configure the level of folding:

Folding Preferences

Folding Preferences

I can fold/unfold portions in my source code like below which greatly improves readability:

Folding Markers

Folding Markers

To have a sneak preview what is inside a folded region, I do not need to unfold it: I simply move my mouse cursor over the + and a hover text will show what is behind it:

Folding Tool Tip

Folding Tool Tip

Summary

Folding makes it easy for me to navigate through big chunks of source files and to focus on the parts which are important. It saves me a lot of scrolling or navigating around.

Happy folding and unfolding :-)

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}