I'm used to Emacs navigation, in particular Ctrl+ P, N, Fand B, but also I also use Jupyter laptops. General question: how to include these shortcuts in a notebook?
What tickles me is that on a Mac these bindings are already installed in the standard Anaconda IP phone. But this is understandable, since most links to the system and browser are tied to Cmdinstead Ctrl.
Since I spend a lot of time in Ubuntu, I wanted to reproduce the same behavior here. It soon became apparent that in most browsers some key bindings were very important, such as Ctrl+ Pfor printing or Ctrl+ Nfor a new window. Disabling them is a huge issue in itself, so I decided to use a different browser exclusively for the Jupyter Notebook, and Vivaldi seems to be a good choice, since all the shortcuts are easily customizable there.
I figured that when you disable browser shortcuts, the IPython syntax will start, but nothing of the kind has happened. Then I tried one of the many tutorials for customizing Jupyter notebook shortcuts (e.g. http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Custom%20Keyboard%20Shortcuts.html ) to link 4 shortcuts that I need. It only works to some extent and only in the built-in magic of Jupyter:
%%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('ctrl-p', 'jupyter-notebook:move-cursor-up')
What he does is that sometimes the cursor in command mode does move up when I press ctrl-p, but this behavior is unstable. Moreover, after moving it, it immediately goes into edit mode in the cell above, which does not happen if I just click the Up arrow. As for the same trick for edit mode:
%%javascript
Jupyter.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-p', 'jupyter-notebook:move-cursor-up')
alas, it does not work at all.
. :
, ? , , Jupyter?
custom.js, . , . alert() .
emacs CodeMirror, , , , , , ? , custom.js?
.
UPD
emacs.js CodeMirror . , .
require(["codemirror/keymap/emacs", "notebook/js/cell", "base/js/namespace"],
function(emacs_keymap, cell, IPython) {
cell.Cell.options_default.cm_config.keyMap = 'emacs';
var cells = IPython.notebook.get_cells();
for(var c=0; c< cells.length ; c++){
cells[c].code_mirror.setOption('keyMap', 'emacs');
}
}
);