I happen to use "Run Selected Text or Current Line in Console" command a lot under the "Run" menu in JupyterLab. How can we configure a custom keyboard shortcut in JupterLab/Jupyter notebook for this?
2 Answers
For JupyterLab
Go to Settings
and choose Advanced Settings editor
. Under the Keyboard shortcuts
tab, copy the entire System Defaults
content to User Preferences
column and find section containing:
"command": "notebook:run-in-console",
"keys": [
""
],
Add the key combination you wish and save, e.g:
"keys": [
"F12"
],

- 5,765
- 3
- 28
- 41
Once JupterLab is open click the Settings dropdown menu. Select Advanced Settings Editor. Select Keyboard Shortcuts. 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.
{"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!

- 111
- 7
-
2What does selector mean? – user147529 Jan 21 '21 at 14:25
-
regarding the question about "selector". (AFAIK) This works in the same way as CSS does. "body" means the html `` tag and ".something" means some html tag with a "something" class. – boclodoa Jun 22 '23 at 18:19