Last active
September 14, 2022 17:56
-
-
Save IamPhytan/9d40ff76955d6e47e029c544dcd6a973 to your computer and use it in GitHub Desktop.
Jupyter Notebook Custom Keyboard Shortcuts / JetBrains keymap ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ~/.jupyter/custom/custom.js | |
/** | |
* | |
* Duplicate a current line in the Jupyter Notebook | |
* Used only CodeMirror API - https://codemirror.net | |
* | |
**/ | |
CodeMirror.keyMap.pcDefault["Ctrl-D"] = function(cm){ | |
// get a position of a current cursor in a current cell | |
var current_cursor = cm.doc.getCursor(); | |
// read a content from a line where is the current cursor | |
var line_content = cm.doc.getLine(current_cursor.line); | |
// go to the end the current line | |
CodeMirror.commands.goLineEnd(cm); | |
// make a break for a new line | |
CodeMirror.commands.newlineAndIndent(cm); | |
// filled a content of the new line content from line above it | |
cm.doc.replaceSelection(line_content); | |
// restore position cursor on the new line | |
cm.doc.setCursor(current_cursor.line + 1, current_cursor.ch); | |
}; | |
/** | |
* | |
* Delete a current line in the Jupyter Notebook | |
* Used only CodeMirror API - https://codemirror.net | |
* | |
**/ | |
CodeMirror.keyMap.pcDefault["Ctrl-Y"] = function(cm){ | |
// delete line | |
CodeMirror.commands.deleteLine(cm); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment