I have recent build of Jupyter than has a menu action allowing you to Restart & Run All:
I would like to add a keyboard shortcut that binds to this action. I have seen the documentation for keyboard customization, but I'm still unsure how to add a keyboard shortcut.
I've built Juypter from source, so based on the help, it would appear that I need to add some code to notebook/static/custom/custom.js
.
I've tried adding the following:
IPython.keyboard_manager.command_shortcuts.add_shortcut('meta-r', function (event) {
IPython.notebook.restart_kernel();
IPython.notebook.execute_run_all();
return false;
});
However, when I press [Meta-r], the kernel seems to restart but execute_run_all() does not get executed.
You can run the notebook document step-by-step (one cell a time) by pressing shift + enter. You can run the whole notebook in a single step by clicking on the menu Cell -> Run All.
For the latest jupyter notebook, (version 5) you can go to the 'help' tab in the top of the notebook and then select the option 'edit keyboard shortcuts' and add in your own customized shortcut for the 'run all' function.
Shift + Enter run the current cell, select below. Ctrl + Enter run selected cells. Alt + Enter run the current cell, insert below. Ctrl + S save and checkpoint.
Just in case someone stumbles upon this post looking for the same answer: you need to wait for the kernel to restart with a timeout before executing. See this discussion on GitHub.
In your case, it would give:
IPython.keyboard_manager.command_shortcuts.add_shortcut('meta-r',
function (event) {
IPython.notebook.kernel.restart();
setTimeout(function(){ IPython.notebook.execute_all_cells(); }, 1000);
return false;
});
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