Nick Sweet
Nick Sweet

Reputation: 2139

Disable Jupyter Keyboard Shortcuts

One of my Jupyter notebooks uses an html <input> tag that expects typed user input, but whenever I type in the text box, command mode keyboard shortcuts activate.

Is it possible to turn off keyboard shortcuts for a single cell or notebook?

Upvotes: 8

Views: 4765

Answers (3)

ijoseph
ijoseph

Reputation: 7163

As per the current 'Customize keymaps' docuemntation, this can now be done using the ~/.jupyter/nbconfig/notebook.json file more simply than hlin117's answer:

For example, to unbind the shortcut to split a cell at the position of the cursor (Ctrl-Shift-Minus)use the following:

// file ~/.jupyter/nbconfig/notebook.json
{
  "keys": {
    "edit": {
      "unbind": [
        "Ctrl-Shift-Minus"
      ]
    },
  },
}

Upvotes: 2

Yinhao Li
Yinhao Li

Reputation: 86

You can use Jupyter.keyboard_manager.disable() to disable the shortcuts temporarily, and use Jupyter.keyboard_manager.enable() to activate again.

Upvotes: 7

hlin117
hlin117

Reputation: 22270

You could copy paste this line into your custom.js:

$([IPython.events]).on("app_initialized.NotebookApp", function () {
    ...
    // Starting from this line, replace 'Shift-k' with whatever 
    // shortcut you're trying to remove.
    IPython.keyboard_manager.command_shortcuts.remove_shortcut('Shift-k')
    ...
});

Or whatever shortcut you wish to remove.

Source: http://akuederle.com/customize-ipython-keymap/

If you want a sample custom.js, this is mine on my github.

Upvotes: 1

Related Questions