我有以下快捷方式配置,在Jupiter笔记本的单元格中运行后可以正常工作:
%%javascript
IPython.keyboard_manager.command_shortcuts.add_shortcut('ctrl-q', {
help: 'Clear all output', // This text will show up on the help page (CTRL-M h or ESC h)
handler: function (event) { // Function that gets invoked
if (IPython.notebook.mode == 'command') {
IPython.notebook.clear_all_output();
return false;
}
return true;
}
});
如何设置Jupyter笔记本以在启动时自动进行初始化?
我尝试将相同的代码(没有%%javascript
)添加到C:\Users\<username>\.ipython\profile_default\static\custom\custom.js
但它没有用。
我只有一个配置文件,使用ipython profile create
,Python 3.3,Windows 7创建。
提前致谢。
custom.js是此代码的正确位置。尝试将其包装如下(不要忘记块结束前的return true
):
$([IPython.events]).on("app_initialized.NotebookApp", function () {
<your code>
return true;
});
在Jupyter notebook的新版本中(使用pip install --upgrade notebook
或使用conda conda upgrade notebook
更新它),您可以从笔记本本身自定义它们。
要执行此操作帮助 - >编辑键盘快捷键
pip install jupyter_contrib_nbextensions
1.更改命令模式快捷方式:请参阅Salvador的回答
2.要更改编辑模式快捷方式:
编辑文件,〜/ .jupyter / nbconfig / notebook.json,如https://jupyter-notebook.readthedocs.io/en/stable/extending/keymaps.html所述
例如,在替换control-enter快捷键以执行代码后,使用macOS上的command-enter,文件如下所示:
{
"Notebook": {
"Toolbar": true,
"Header": true
},
"Cell": {
"cm_config": {
"lineNumbers": true
}
},
"keys": {
"command": {
"unbind": [
"ctrl-enter"
],
"bind": {
"cmdtrl-enter": "jupyter-notebook:run-cell"
}
},
"edit": {
"unbind": [
"ctrl-enter"
],
"bind": {
"cmdtrl-enter": "jupyter-notebook:run-cell"
}
}
}
}