如何将键盘快捷键永久添加到Jupyter(ipython)笔记本? [英] How to add keyboard shortcuts permanently to Jupyter (ipython) notebook?
问题描述
我有以下快捷方式配置,在Jupiter笔记本单元格中运行后有效:
I have the following configuration for shortcuts, that works after running it in the cell of Jupiter notebook:
%%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;
}
});
如何在启动时自动设置Jupiter笔记本进行初始化?
How can I setup Jupiter notebook to make this initialization automatically on startup?
我尝试将相同的代码(不含 %% javascript
)添加到 C:\ Users \< username> ; \ .ipython \profile_default\static \custom\custom.js
但它没有用。
I tried adding the same code (without %%javascript
) to C:\Users\<username>\.ipython\profile_default\static\custom\custom.js
but it didn't work.
我有只有一个配置文件,使用 ipython配置文件创建
,Python 3.3,Windows 7创建。
I have only one profile, created with ipython profile create
, Python 3.3, Windows 7.
提前致谢。
推荐答案
custom.js是此代码的正确位置。尝试将其包装如下(在块结束之前不要忘记 return true
):
custom.js is the correct place for this code. Try wrapping it as follows (don't forget the return true
before the end of the block):
$([IPython.events]).on("app_initialized.NotebookApp", function () {
<your code>
return true;
});
这篇关于如何将键盘快捷键永久添加到Jupyter(ipython)笔记本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!