Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize keyboard shortcuts in Jupyter Lab to run current line or selected text?

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?

like image 594
Vinay Avatar asked Oct 09 '19 18:10

Vinay


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"
],
like image 169
vs97 Avatar answered Sep 19 '22 07:09

vs97


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!

Source

like image 24
Chandler B Avatar answered Sep 21 '22 07:09

Chandler B