Skip to content

Instantly share code, notes, and snippets.

@dshulchevskiy
Last active May 28, 2020 14:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dshulchevskiy/a0b43fbbfbed75bb285a73b88f2ca933 to your computer and use it in GitHub Desktop.
Save dshulchevskiy/a0b43fbbfbed75bb285a73b88f2ca933 to your computer and use it in GitHub Desktop.
Sublime shortcut for jupyter notebook
"""
Sublime shortcuts for jupyter notebook
"""
from jupyter_core.paths import jupyter_config_dir
import os
custom_js_path = os.path.join(jupyter_config_dir(), 'custom', 'custom.js')
custom_path = os.path.join(jupyter_config_dir(), 'custom')
js_script_for_sublime_shortcuts = """
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) {}
});
}
}
);
"""
if not os.path.exists(custom_path):
os.makedirs(custom_path)
with open(custom_js_path, 'a') as f:
f.write(js_script_for_sublime_shortcuts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment