In Google Colab, is it possible to expand/collapse all section toggles using a shortcut?
Asked Answered
S

2

6

I'm using Gooogle Colab to keep a record of code I learn whilst working through the 'Google IT Automation with Python' course.

I use the table of content feature to group sections of code by topic. These sections can be toggled in the main window to show or hide their content.

However, with so much code building up, I would like a way to quickly close all toggles e.g. as shown in the picture.

(Alternatively, if anyone has a better method or can recommend a better platform for building, testing and organising code snippets in a way that is easily retrievable, I'd welcome the recommendation).

Thanks!

enter image description here

Shanklin answered 8/1, 2022 at 16:55 Comment(0)
T
7

Note: Updated the original answer in May 2024 since the original shortcut no longer works.


Current answer

To open or close all sections in a Colab notebook at once, you first select all cells, then collapse/expand them.

  1. Ctrl + Shift + A: select all cells
  2. One of the following:
    1. Ctrl + [: expand selection
    2. Ctrl + ]: collapse selection

Please note that, in edit mode (when you have a blinking cursor), Ctrl + ] and Ctrl + [ means "indent" and "dedent" respectively1.

You can find a list of all available commands at "Tools" menu -> "Command palette" (go ahead and have a glance; it's worth it!).


Original answer

  • Ctrl + ] invokes "Collapse all/select sections" in command mode (not editing a cell).

  • Ctrl + [ after hitting Ctrl + ] expanded all cells in my experiment, but this is not documented.


1 source: https://gist.github.com/discdiver/9e00618756d120a8c9fa344ac1c375ac#shortcuts-when-in-edit-mode-inside-a-cell-with-a-blinking-cursor

Tendance answered 9/1, 2022 at 11:49 Comment(2)
For me it just collapses the current section :(Eligibility
Thanks for Ctrl+Shift+A. I tried to select all with Ctrl+A and gave up hope :)Eligibility
D
3

If Ctrl + ] or Ctrl + ] with keyboard shouldn't be work you can find a voice that invokes "Collapse/Expand sections" in View->Collapse/Expand sections.

Desolation answered 26/1, 2022 at 19:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.