How to Customize JupyterLab Keyboard Shortcuts

Jeff Hale
Towards Data Science
3 min readSep 24, 2018

--

I often find myself wanting to restart and run all cells, so I wanted to make a keyboard shortcut. I made this tutorial to help other folks out, because it’s not a one-click-selection kind of thing

JupyterLab is like Jupyter notebook on anabolic steroids — without the increased cancer risk and other negative side effects. JupyterLab is billed as the next generation UI for Project Jupyter. It was released in beta in early 2018.

Fun fact, the Jupyter folks write JupyterLab as one word but Jupyter notebook as two 😃.

It feels much like using your familiar Jupyter notebook with enhanced functionality such as navigation tabs. It’s the future — and it’s here now.

If you’re like me you might have seen JupyterLab in Anaconda but kept to your trusty Jupyter notebook. Try it. It can help you enhance your productivity. Speaking of productivity, let’s make a keyboard shortcut. 🚀

Doing It

Install with conda install -c conda-forge jupyterlab or pip install jupyterlab. Then run JupyterLab in the terminal with jupyterlab or by selecting the app icon in Anaconda Navigator.

screenshot of jupyter lab

Once JupterLab is open click the Settings dropdown menu. Select Advanced Settings Editor.

screenshot of menu

Select Keyboard Shortcuts.

screenshot of advanced options

You’ll see a dictionary for each option in the System Defaults panel. There are a bunch of options, so you might want to Command + F (Ctrl + F on Windows) to find the one you want. Copy the code of the one you want to override.

Here’s the section for restart-and-run-all.

{
"command": "runmenu:restart-and-run-all",
"keys": [
""
],
"selector": "[data-jp-code-runner]"
},

Paste this code in the User Preferences panel. Type the names of whichever keys you want to make your shortcut in the keys list. I added Ctrl and Shift and R below.

Update June 24, 2020, Shahida pointed out in the comments that JupyterLab had changed its API for changing keyboard shortcuts. The code below is updated. Thank you Shahida!

{"shortcuts": 
[
{
"command": "runmenu:restart-and-run-all",
"keys": [
"Ctrl Shift R"
],
"selector": "[data-jp-code-runner]"
}
]
}

I suggest making sure you aren’t overriding another JupyterLab keyboard shortcut by searching the System Defaults Panel for your new key combination.

And there you have it. Press Command + S (Ctrl + S on Windows) to save, open a notebook file, and try out your new keyboard shortcut!

Run All!

restart kernel screenshot

Heck yeah!

You just learned how to save yourself time by making keyboard shortcuts in JupyterLab. Note that this will run in Edit mode or Command mode in Jupyter Lab.

Some commands don’t show up in the System Defaults panel. Here’a a list of the commands that can be bound.

Experiment and enjoy!

Wrap

I hope you found this guide to customizing JupyterLab shortcuts to be helpful. If you did, please share it on your favorite social media so other folks can find it, too. 😀

I write about Python, SQL, and other tech topics. If any of that’s of interest to you, sign up for my mailing list of awesome data science resources and read more to help you grow your skills here. 👍

data awesome email signup form

--

--

I write about data things. Follow me on Medium and join my Data Awesome mailing list to stay on top of the latest data tools and tips: https://dataawesome.com