##// END OF EJS Templates
Merge pull request #8778 from SylvainCorlay/Meta...
Merge pull request #8778 from SylvainCorlay/Meta Use isinstance to check for types

File last commit:

r21631:3ac9be53 merge
Show More
Custom Keyboard Shortcuts.ipynb
113 lines | 2.9 KiB | text/plain | TextLexer
/ examples / Notebook / Custom Keyboard Shortcuts.ipynb

Keyboard Shortcut Customization

Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the IPython JavaScript API. Here is an example that makes the r key available for running a cell:

In [ ]:

IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {
    help : 'run cell',
    help_index : 'zz',
    handler : function (event) {
        return false;

There are a couple of points to mention about this API:

  • The help_index field is used to sort the shortcuts in the Keyboard Shortcuts help dialog. It defaults to zz.
  • When a handler returns false it indicates that the event should stop propagating and the default action should not be performed. For further details about the event object or event handling, see the jQuery docs.
  • If you don't need a help or help_index field, you can simply pass a function as the second argument to add_shortcut.
In [ ]:

IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {
    return false;

Likewise, to remove a shortcut, use remove_shortcut:

In [ ]:


If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your <profile>/static/custom/custom.js file.