Jump to next code cell (IPython notebook)

三世轮回 提交于 2019-12-24 05:22:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!