google-colaboratorykeyboard-shortcutstogglebutton

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


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


Solution

  • 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


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