如何将键盘快捷键永久添加到Jupyter(ipython)笔记本?

问题描述 投票:11回答:4

我有以下快捷方式配置,在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创建。

提前致谢。

ipython ipython-notebook startup jupyter-notebook jupyter
4个回答
8
投票

custom.js是此代码的正确位置。尝试将其包装如下(不要忘记块结束前的return true):

$([IPython.events]).on("app_initialized.NotebookApp", function () {
    <your code>

    return true;
});

7
投票

Jupyter notebook的新版本中(使用pip install --upgrade notebook或使用conda conda upgrade notebook更新它),您可以从笔记本本身自定义它们。

要执行此操作帮助 - >编辑键盘快捷键

enter image description here


4
投票

Adding hotkeys the easy way with nbextensions

  1. 安装nbextensionspip install jupyter_contrib_nbextensions
  2. 然后推出jupyter笔记本。
  3. 介绍页面将有一个名为nbextensions的新选项卡单击它并启用键盘快捷键编辑器。
  4. 现在打开任何笔记本点击帮助>键盘快捷键
  5. 如果单击它,每个快捷方式旁边都会有一个铅笔图标,然后您可以将快捷方式设置为您想要的任何快捷方式。

1
投票

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"
      }  
    } 
  }   
} 
© www.soinside.com 2019 - 2024. All rights reserved.