跳转到下一个代码单元格(IPython笔记本)

时间:2014-04-06 17:46:03

标签: user-interface customization ipython ipython-notebook

我使用IPython 2.0 Notebook进行教学。

笔记本在教学会话之前创建,并在会话期间按原样使用。

当然,当我准备笔记本时,我有意识地按顺序访问所有单元格(实际上,我不会)。

回到课堂上,当我向学生展示概念和代码时,我不需要把焦点放在下一个单元格上,我只需要光标在下一个代码中等待单元格......

我希望最好的是有人能够更改Shift-Enter的默认行为,以便它执行当前单元格,并跳转到下一个可执行文件单元格。

它已经完成了吗?

1 个答案:

答案 0 :(得分:4)

在IPython Notebook示例中描述了在2.x中重新定义键盘快捷键:

http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Notebook/User%20Interface.ipynb

以下是我使用shift-enter转到下一个codecell并保持编辑模式:

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);