JupyterLab:如何使用键盘快捷键清除当前单元格的输出? [英] JupyterLab: How to clear output of current cell using a keyboard shortcut?

查看:507
本文介绍了JupyterLab:如何使用键盘快捷键清除当前单元格的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已为Jupyter 笔记本询问并回答了此问题

This question has been asked and answered for Jupyter Notebooks here. There is one suggestion regarding JupyterLab there as well on how to hide cell output, but not to clear it.

使用Edit > Clear Outputs下的菜单,这非常容易.但是,如何使用键盘快捷键来实现呢? Edit下的许多其他命令已经有自己分配的快捷方式,但是没有这个快捷方式:

This is easy enough using the menu under Edit > Clear Outputs. But how do you do it using a keyboard shortcut? Many other commands under Edit already have their own assigned shortcuts, but not this one:

推荐答案

答案:

您必须在Settings > Advanced Settings Editor下分配一个自定义快捷键,方法是在User Preferences下插入以下内容:

You'll have to assign a custom shortcut key under Settings > Advanced Settings Editor by inserting the following under User Preferences:

{// List of Keyboard Shortcuts
    "shortcuts": [
        {
            "command": "notebook:clear-cell-output",
            "keys": [
                "F10"
            ],
            "selector": ".jp-Notebook.jp-mod-editMode"
        },
    ]
}

我去过F10,但是大多数其他按键或按键组合也应该起作用.我也用过Ctrl Shift Enter.

I went for F10, but most other keys or combination of keys should work too. I've also used Ctrl Shift Enter.

放置位置:

一些详细信息:

如果您分配了其他快捷方式,请确保将其添加到其他快捷方式列表中的正确位置.

If you've assigned other shortcuts, make sure to add it in the correct place in the list of other shortcuts.

{// List of Keyboard Shortcuts
    "shortcuts": [
        {
            "command": "notebook:run-in-console",
            "keys": [
                "F9"
            ],
            "selector": ".jp-Notebook.jp-mod-editMode"
        },
        {
            "command": "notebook:clear-cell-output",
            "keys": [
                "F10"
            ],
            "selector": ".jp-Notebook.jp-mod-editMode"
        },
    ]
}

还有一个谜:

如果在第二个框中插入 exact 相同的内容,则会看到Run > Run Selected Text or Current Line in Console项旁边有一个漂亮的F9:

If you insert the exact same thing as in the second box, you'll see that the item Run > Run Selected Text or Current Line in Console has gotten a nice F9 right next to it:

Edit > Clear Outputs会是 不是 ,我不得不说我不知道​​为什么.

This will not be the case for the item Edit > Clear Outputs, and I'll have to say that I don't know why.

据我所知,您分配给所选键盘快捷键的"command": "notebook:clear-cell-output"应该具有确切的功能.但好处是它可以完全一样地工作.至少对我有用.

To my knowledge the "command": "notebook:clear-cell-output" that you're assigning to your chosen keyboard shortcut should be that exact functionality. But the good thing is that it works perfectly all the same. At least it does for me.

请注意,这种方法最适合JupyterLab的较新版本.对于较旧的版本,正确的方法会有所不同.

Please note that this approach works best for newer versions of JupyterLab. The correct way will be a bit different for older versions.

下面是一个可立即对其进行测试的python代码段:

Here's a python snippet to test it out right away:

import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
print(df)

这篇关于JupyterLab:如何使用键盘快捷键清除当前单元格的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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