How to quickly add shortcuts to keys in Jupyter (ipython)?

I have the following configuration for shortcuts that works after launching in the cell of a Jupiter laptop:

%%javascript IPython.keyboard_manager.command_shortcuts.add_shortcut('ctrl-q', { help: 'Clear all output', // This text will show up on the help page (CTRL-M h or ESC h) handler: function (event) { // Function that gets invoked if (IPython.notebook.mode == 'command') { IPython.notebook.clear_all_output(); return false; } return true; } }); 

How to configure a Jupiter laptop to automatically initialize at startup?

I tried adding the same code (without %%javascript ) to C:\Users\<username>\.ipython\profile_default\static\custom\custom.js , but it did not work.

I have only one profile created using ipython profile create , Python 3.3, Windows 7.

Thanks in advance.

+11
ipython ipython-notebook jupyter-notebook jupyter startup
source share
4 answers

custom.js is the right place for this code. Try wrapping it like this (remember to return true to the end of the block):

 $([IPython.events]).on("app_initialized.NotebookApp", function () { <your code> return true; }); 
+8
source share

In the new version of Jupyter notebook (upgrade it either using pip install --upgrade notebook , or if you use conda conda upgrade notebook ), you can configure them from the notebook itself.

To do this, HelpEdit keyboard shortcuts

enter image description here

+6
source share

Adding hotkeys in an easy way with nbextensions

  • Install nbextensions .
    pip install jupyter_contrib_nbextensions
  • Then run jupyter notebook.
  • On the input page there will be a new tab called nbextensions, click it and enable the keyboard shortcut editor.
  • Now open any mouse click on the laptop> keyboard shortcuts
  • Each shortcut will have a pencil icon next to it, if you click on it, then you can set the shortcut to whatever you want.
+2
source share

1. To change command mode shortcuts: see El Salvador's Answer

2. To change the editing mode shortcuts:

Edit the ~ / .jupyter / nbconfig / notebook.json file as described in https://jupyter-notebook.readthedocs.io/en/stable/extending/keymaps.html.

For example, after replacing the control-enter shortcut to execute code on command-enter in macOS, the file looks like this:

 { "Notebook": { "Toolbar": true, "Header": true }, "Cell": { "cm_config": { "lineNumbers": true } }, "keys": { "command": { "unbind": [ "ctrl-enter" ], "bind": { "cmdtrl-enter": "jupyter-notebook:run-cell" } }, "edit": { "unbind": [ "ctrl-enter" ], "bind": { "cmdtrl-enter": "jupyter-notebook:run-cell" } } } } 
0
source share

All Articles