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

Taa*_*aar 2 user-interface customization ipython ipython-notebook

我使用 IPython 2.0 Notebook 进行教学。

笔记本是在教学课程之前创建的,并在课程期间按原样使用。

当然,当我准备笔记本时,我按顺序访​​问所有单元格是有意义的(实际上,我没有)。

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

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

已经完成了吗?

小智 5

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

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

这是我用来让 shift-enter 转到下一个代码单元并保持编辑模式的方法:

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);            
Run Code Online (Sandbox Code Playgroud)