Reputation: 1939
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?
Upvotes: 5
Views: 1059
Reputation: 13980
Individual Sublime Text key bindings can be disabled using the unbound
command in your Default (OS).sublime-keymap
file. i.e. Menu --> Preferences --> Key Bindings - User
. In your case simply add the following line.
{ "keys": ["ctrl+enter"], "command": "unbound" },
Since the Add Line.sublime-macro
is quite useful you may wish to give it another binding, for example you could use alt+enter
or super+enter
in which case you would add the following.
{ "keys": ["ctrl+enter"], "command": "unbound" },
{ "keys": ["alt+enter"], "command": "run_macro_file", "args":
{"file": "res://Packages/Default/Add Line.sublime-macro"} },
Upvotes: 0
Reputation: 641
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) {}
});
}
}
);
Upvotes: 9
Reputation: 81
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
Upvotes: 5