8. Collapsing child code

Code can get long and scrolling through it to find important elements can become tiring.

One trick Integrated Development Environments (IDE's) have is to collapse (fold) code that is a child of a parent element.

With the mouse:

  • Hover over the lines numbers in the editor.
  • Click the - button by the element to collapse.
  • Click again to expand.

With the keyboard:

  • Place the cursor on any of the child elements.
  • Press Ctrl-Shift-[
  • Press Ctrl-Shift-] on the parent element to expand.

You can also fold / unfold every collapsible element at once using a key combo:

  • Ctrl - K then Ctrl - 0 (zero) to fold
  • Ctrl - K then Ctrl - J (zero) to unfold