Eclipse Folding

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 🙂

6 thoughts on “Eclipse Folding

  1. Pingback: Eclipse Folding | MCU on Eclipse | Laughing

  2. Nice to use Ctrl+Numpad_Add and Ctrl+Numpad_Substract to expand/collapse the block where your caret currently is, instead of using mouse. Also to reset the whole structure (collapse all) by Ctrl+Shift+Numpad_Divide

    Like

  3. hmmm… would have been nice to be able to fold arbitrary selections in a source code editor, though, which has always been quite common in programmer’s editors:-(

    Like

    • Yes, folding is on control blocks or within language source structures. Interesting point about ‘true’ arbitrary source folding. Although I prefer to fold by functions or functional blocks.

      Like

  4. Pingback: Eclipse Gems, Tips & Tricks: Code Folding | MCU on Eclipse

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.