Keyboard shortcuts for Jupyter Lab

setup
Jupyter
Published

February 24, 2023

Modified

March 3, 2023

Introduction

Keyboard shortcuts are a great way to speed up your workflow in Jupyter Lab, but sometimes the default shortcuts don’t quite fit your needs. In this short post, I’ll show you how to add four new keyboard shortcuts to Jupyter Lab that I find useful.

shortcut function
Ctrl Shift Enter Run All Above Selected Cell
Alt L Clear All Outputs
Alt M Render All Markdown Cells
Shift V Paste Cells Above

Editing the settings

Go to Settings → Advanced Settings Editor → JSON Settings Editor

Then add these shortcuts at the end of the file.

        {
            "args": {},
            "command": "notebook:run-all-above",
            "keys": [
                "Ctrl Shift Enter"
            ],
            "selector": ".jp-Notebook:focus"
        },
        {
            "args": {},
            "command": "notebook:clear-all-cell-outputs",
            "keys": [
                "Alt L"
            ],
            "selector": ".jp-Notebook:focus"
        },
        {
            "args": {},
            "command": "notebook:render-all-markdown",
            "keys": [
                "Alt M"
            ],
            "selector": ".jp-Notebook:focus"
        },
        {
            "args": {},
            "command": "notebook:paste-cell-above",
            "keys": [
                "Shift V"
            ],
            "selector": ".jp-Notebook:focus"
        }

Remember to add a trailing comma on the previous entry, and no comma after the final entry.

Conclusion

With these new keyboard shortcuts, you can quickly run all the cells above your current selection, clear all cell outputs, render all markdown cells, and paste cells above your current selection. By customizing your shortcuts to fit your needs, you can save time and increase your productivity in Jupyter Lab.