In the IPython Notebook environment, it is possible to define custom keyboard shortcuts using the IPython Javascript API. Using the %%javascript
magic, one may write a javascript within IPython's interactive console as follows (example described here):
%%javascript
IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {
help : 'run cell',
help_index : 'zz',
handler : function (event) {
IPython.notebook.execute_cell();
return false;
}}
);
I'd like to write a javascript that creates a shortcut during edit mode that binds Ctrl-Alt-Down to the action of 'duplicate current line'---that is, move the cursor to the start of the current line, select the line, copy the line, return, paste. Essentially, I want to emulate the keyboard shortcut of Eclipse, or Ctrl-d in Notepad++, or C-a C-SPACE C-n M-w C-y in Emacs. The javascript file will take the form of the following:
%%javascript
IPython.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-alt-down', {
help : 'run cell',
help_index : 'zz',
handler : function (event) {
[Code that duplicates the line];
return false;
}}
);
though my attempts suggest 'ctrl-alt-down' is the incorrect way to represent the shortcut sequence, and I can't find any documentation for the keyboard_manager
.
I'd rather not go with an (e.g.,) AutoHotKey solution since I want to restrict this shortcut to the edit mode of IPython Notebook.