Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter lab shortcuts

I've been using Jupyter Notebooks for a couple of years now. I've just headed over to Jupyter Lab, but I've found the lack of shortcuts to be a burden.

For example, I noticed that I can search for commands in the left hand palette. But I can't seem to easily bind them to a keyboard shortcut. Is this even possible?

For example, I want to collapse the current cell output with "O" and collapse all code cells with "Shift O".

enter image description here

like image 539
Daniel Severo Avatar asked Mar 14 '18 14:03

Daniel Severo


People also ask

How do I get Jupyter shortcuts?

Press 'Enter' to change the cell into the edit mode. You can modify the command mode shortcuts by using the help menu. Click on the 'Help' and choose the 'Edit keyboard shortcuts' option. The following interface shows in the Jupyter notebook where you can define new keyboard shortcuts.

How do I insert a cell in JupyterLab?

Enter enter edit mode in the active cell. Scroll up with the up arrow. Scroll down with the down arrow. A insert a new cell above the active cell.

How do I add a shortcut to Jupyter?

Starting with Jupyter Notebook 5.0, you can customize the command mode shortcuts from within the Notebook Application itself. Head to the ``Help`` menu and select the ``Edit keyboard Shortcuts`` item. A dialog will guide you through the process of adding custom keyboard shortcuts.


2 Answers

This question is answered on GitHub here. You can also look here for the correct command names to enter in your keyboard shortcut user overrides because they are not always the same as what is shown in the Commands side-bar.

The following are some that I use:

{   "shortcuts": [     {       "command": "notebook:hide-cell-outputs",       "keys": [         "O"       ],       "selector": ".jp-Notebook:focus"     },         {       "command": "notebook:show-cell-outputs",       "keys": [         "O",          "O"       ],       "selector": ".jp-Notebook:focus"     },          {       "command": "notebook:hide-all-cell-outputs",       "keys": [         "Ctrl L"       ],       "selector": ".jp-Notebook:focus"     },      {       "command": "notebook:hide-all-cell-code",       "keys": [         "Shift O"       ],       "selector": ".jp-Notebook:focus"     }   ] } 

which allows you to hide a cell output by pressing O once and showing the cell output by pressing O twice. The last one collapses all cell code with Shift + O as you requested.

like image 186
jeschwar Avatar answered Oct 15 '22 20:10

jeschwar


On keyboards shortcuts of advance settings this code works fine for moving cells up and down

{     // Move cell up     "shortcuts": [         {       "selector": ".jp-Notebook:focus",       "command": "notebook:move-cell-up",       "keys": [         "Alt ArrowUp"       ]         },     // Move cell down         {       "selector": ".jp-Notebook:focus",       "command": "notebook:move-cell-down",       "keys": [         "Alt ArrowDown"       ]     }     ]  } 

move cell up and down

like image 29
MertTheGreat Avatar answered Oct 15 '22 19:10

MertTheGreat