Skip to content

Instantly share code, notes, and snippets.

@pedroarthur
Created October 13, 2017 16:16
Show Gist options
  • Save pedroarthur/d3517e28d5f6f44b714b74e4c8a0568b to your computer and use it in GitHub Desktop.
Save pedroarthur/d3517e28d5f6f44b714b74e4c8a0568b to your computer and use it in GitHub Desktop.
function run_and_focus (event) {
var note = IPython.notebook;
var current_cell = note.get_selected_cell();
note.execute_cell_range(note.get_selected_index(), note.ncells());
current_cell.focus_cell();
return false;
}
function run_before_and_focus (event) {
var note = IPython.notebook;
var current_cell = note.get_selected_cell();
note.execute_cell_range(0, note.get_selected_index()+1);
current_cell.focus_cell();
return false;
}
function to_cell (cell) {
var note = IPython.notebook;
note.get_cell(cell).focus_cell();
return false;
}
function set_up_shortcuts () {
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Ctrl-b', {
help : 'run this cell and the cells below',
help_index : 'zz',
handler : run_and_focus
}
);
Jupyter.keyboard_manager.edit_shortcuts.add_shortcut('Ctrl-b', {
help : 'run this cell and the cells below',
help_index : 'zz',
handler : run_and_focus
}
);
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Ctrl-Shift-b', {
help : 'run from begining till this cell',
help_index : 'zz',
handler : run_before_and_focus
}
);
Jupyter.keyboard_manager.edit_shortcuts.add_shortcut('Ctrl-Shift-b', {
help : 'run from begining till this cell',
help_index : 'zz',
handler : run_before_and_focus
}
);
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Ctrl-Home', {
help : 'go to the first cell',
help_index : 'zz',
handler : function (event) {
return to_cell(0);
}
}
);
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Ctrl-End', {
help : 'go to the last cell',
help_index : 'zz',
handler : function (event) {
return to_cell(IPython.notebook.ncells()-1);
}
}
);
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Z', {
help : 'scroll to current cell',
help_index : 'zz',
handler : function (event) {
IPython.notebook.scroll_to_cell(IPython.notebook.get_selected_index());
return false;
}
}
);
return true;
}
$([IPython.events]).on("app_initialized.NotebookApp", set_up_shortcuts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment