In a command line Python session I can press Control-P to retrieve the previously entered line edit it.
How can I perform a similar operation in Jupyter, i.e. carry forward the contents of the previous "In:" block?
Looks like Jupyter doesn't have such a feature out of the box, although, you could write your own custom keyboard shortcut using CodeMirror API: https://codemirror.net/doc/manual.html
First you need to create your own custom.js
file:
http://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/JavaScript%20Notebook%20Extensions.html#custom.js
You could try something like this (depending on what you're expecting to get):
CodeMirror.keyMap.pcDefault["Ctrl-P"] = function(cm) {
var selected = Jupyter.notebook.get_selected_cell();
if (!Jupyter.notebook.get_prev_cell(selected)) {
// This is the first cell
return;
}
Jupyter.notebook.select_prev();
Jupyter.notebook.copy_cell();
Jupyter.notebook.select_next();
Jupyter.notebook.paste_cell_replace();
Jupyter.notebook.handle_edit_mode(selected);
}
This will copy the contents of the cell above and insert it into the currently selected cell. You could replace paste_cell_replace()
method with paste_cell_above()
to create a new cell instead of replacing the contents of the currently selected one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With