问题
I use the IPython 2.0 Notebook for teaching.
The notebooks are created before the teaching session, and used as-is during the session.
Sure, when I prepare the notebook, it has sense that I access all the cells in sequence (actually, I don't).
Back in class, while I present the concepts and the code to the students, I don't need the focus to be put on the next cell, I just need the cursor to wait in the next code cell...
The best I can hope is that someone has been able to change the default behaviour of Shift-Enter, so that it executes the current cell, and jump to the next executable cell.
Has it been done?
回答1:
Redefining keyboard shortcuts in 2.x is described in the IPython Notebook examples:
http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Notebook/User%20Interface.ipynb
Here is what I use to have shift-enter go to the next codecell and stay in edit mode:
var add_edit_shortcuts = {
'shift-enter' : {
help : 'run cell, select next codecell',
help_index : 'bb',
handler : function (event) {
IPython.notebook.execute_cell_and_select_below();
// find next CodeCell and go into edit mode if possible, else stay in next cell
var i;
for (i = IPython.notebook.get_selected_index(); i < IPython.notebook.ncells() ;i++) {
var cell = IPython.notebook.get_cell(i);
if (cell instanceof IPython.CodeCell) {
IPython.notebook.select(i);
IPython.notebook.edit_mode();
break;
}
}
return false;
}
},
};
IPython.keyboard_manager.edit_shortcuts.add_shortcuts(add_edit_shortcuts);
来源:https://stackoverflow.com/questions/22897631/jump-to-next-code-cell-ipython-notebook