Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Ctrl+Enter sublime keymap in jupyter notebook

I'm using Jupyter Notebook with the Sublime Text keymap, by adding the following to my Jupyter custom.js:

require(["codemirror/keymap/sublime", "notebook/js/cell"], 
function(sublime_keymap, cell) {
    cell.Cell.options_default.cm_config.keyMap = 'sublime';
});

...which works great mostly, except that I'm on a Windows machine and this adds the Sublime functionality of "insertLineAfter" to the binding for Ctrl+Enter, which I don't want because Ctrl+Enter is the binding to execute the current cell in Jupyter.

Does anyone know how to disable just the "insertLineAfter" binding for Ctrl+Enter please?

like image 457
user1684046 Avatar asked Apr 03 '16 11:04

user1684046


2 Answers

Following worked for me:

require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
    function(sublime_keymap, cell, IPython) {
        cell.Cell.options_default.cm_config.keyMap = 'sublime';
        cell.Cell.options_default.cm_config.extraKeys["Ctrl-Enter"] = function(cm) {}
        var cells = IPython.notebook.get_cells();
        for(var cl=0; cl< cells.length ; cl++){
            cells[cl].code_mirror.setOption('keyMap', 'sublime');
            cells[cl].code_mirror.setOption("extraKeys", {
                "Ctrl-Enter": function(cm) {}
            });
        }
    } 
);
like image 157
William Saunders Avatar answered Nov 01 '22 21:11

William Saunders


you can prevent the ctrl+enter produce a new line in jupyter notebook by comment out the following line:

cmds[map[ctrl + "Enter"] = "insertLineAfter"] = function(cm) { insertLine(cm, false); };

in the file:

[python lib path]/dist-packages/notebook/static/components/codemirror/keymap/sublime.js
like image 40
Junzi Avatar answered Nov 01 '22 20:11

Junzi