【问题标题】:Any way to swap Enter and Shift-Enter input commands in Edit-Mode, Jupyter Notebook?有什么方法可以在 Jupyter Notebook 的编辑模式中交换 Enter 和 Shift-Enter 输入命令?
【发布时间】:2017-08-04 08:06:28
【问题描述】:

我刚开始使用 ipython/jupyter 笔记本。 Shift-Enter(运行当前单元格)和 Enter(插入换行符)命令使用起来令人沮丧。我想在编辑模式下交换这两个输入的命令。

所以:

Shift-Enter:(插入换行符)

输入:(运行当前单元格)

有没有办法重新映射 jupyter notebook 的命令?可能是配置文件?听起来 ipython notebook 并不总是以这种方式工作(Enter in the IPython console inserts new line instead of executing current line after kernel restart #2696)。链接的github问题的解决方案似乎是“只需使用shift-enter”,我无法在google上找到解决方案。

我有以下版本:

ipykernel (4.5.2)
ipython (5.3.0)
jupyter (1.0.0)
notebook (4.4.1)

【问题讨论】:

  • 不是要搞死灵术,但由于大多数即时通讯工具都使用它交换,我会对答案非常感兴趣。

标签: ipython ipython-notebook jupyter-notebook


【解决方案1】:

打开一个笔记本,在[帮助]下可以找到[编辑键盘快捷键]。对于 5.0 之前的版本,我在下面链接的文档详细说明了可以运行什么命令来更改快捷方式。

来源:https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Custom%20Keyboard%20Shortcuts.html

【讨论】:

  • 我也遇到了同样的问题,这个解决方案似乎不起作用,因为快捷方式位于“编辑”模式,显然无法更改。
【解决方案2】:

编辑:

在较新的 JupyterLab(我现在使用 2.2.5)上,现在有一个键盘快捷键设置文件(在设置 > 高级设置编辑器下)。不幸的是,似乎 Shift+Enter 和 Enter 之间的交换不再可能,因此当添加 Enter 作为 run-current-cell 键时,Shift+Enter 仍然运行当前单元格(即,如果将 Enter 添加为运行-current-cell 键,它不能再在当前单元格中添加新行)。

老答案:

一个老问题,但对于使用 JupyterLab(版本 0.35.6,Windows 10)的人来说值得回答:

  1. 转到设置 > 高级设置编辑器。设置选项卡将打开。
  2. 在“设置”选项卡的侧边栏上,单击“键盘快捷键”。将打开两个内部选项卡:系统默认值和用户覆盖。
  3. 将以下内容复制到 User Overrides 以将 Shift+Enter 替换为 Enter(请注意,无需将 Shift+Enter 明确定义为“换行”的键盘快捷键)。

这里的实际覆盖是值“Enter”,它替换了默认值“Shift Enter”:

    {
       "runmenu:run": {
          "command": "runmenu:run",
          "keys": [
             "Enter"
          ],
          "selector": "[data-jp-code-runner]",
          "title": "Run",
          "category": "Run Menu"
      }, 
      "notebook:run-cell-and-select-next": {
          "command": "notebook:run-cell-and-select-next",
          "keys": [
            "Enter"
          ],
          "selector": ".jp-Notebook.jp-mod-editMode",
          "title": "Run Cell and Select Next",
          "category": "Notebook Operations"
       }
    }
  1. 点击右上角的保存图标。

最终结果:

【讨论】:

    猜你喜欢
    • 2022-09-22
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2023-03-13
    • 2015-05-21
    • 1970-01-01
    • 2010-10-10
    相关资源
    最近更新 更多