pythonjupyter-lab

How to enable code folding in Jupyter Lab


Running JupyterLab version 3.0.0 and would like to enable code folding (collapse classes, functions etc in Python). I have followed the instructions in this Jupyter Lab github post:

Under Settings / Text Editor, I have these User preferences (right pane):

{
    "editorConfig": {
        "lineNumbers": true,
        "codeFolding": true
    }
}

And I do not see any triangles appearing on the left side of the cells. What else do I need to do in order to enable code folding?

For abundance of clarity, this question pertains to JupyterLab specifically.


Solution

  • Those instructions are specifically for the text editor, not the notebook interface.

    Try this instead, in Settings / Notebook:

    {
        "codeCellConfig": {
            "codeFolding": true
        }
    }
    

    If you want to enable code folding for Markdown or raw cells, see markdownCellConfig and rawCellConfig respectively.