跳至下一个代码单元(IPython笔记本) [英] Jump to next code cell (IPython notebook)

查看:90
本文介绍了跳至下一个代码单元(IPython笔记本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IPython 2.0笔记本进行教学.

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...

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

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.

完成了吗?

推荐答案

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

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

在这里,我使用shift键进入下一个代码单元并保持编辑模式:

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

这篇关于跳至下一个代码单元(IPython笔记本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆