Reputation: 11793
Does anyone know what is the keyboard shortcut to clear (not toggle) the cell output in Jupyter Notebook?
Upvotes: 100
Views: 181265
Reputation: 301
Adding for JupyterLab users. Ctrl, or Cmd, (advanced settings) and pasting the below in User References under keyboard shortcuts does the trick for me.
{
"shortcuts": [
{
"command": "notebook:hide-cell-outputs",
"keys": [
"H"
],
"selector": ".jp-Notebook:focus"
},
{
"command": "notebook:show-cell-outputs",
"keys": [
"Shift H"
],
"selector": ".jp-Notebook:focus"
}
]
}
Upvotes: 15
Reputation: 31
To delete/clear individual cell outputs in JupyterLab (without going to Edit > Clear Output), go to Settings > Advanced Settings Editor (Ctrl+,) > Keyboard Shortcuts
and add this to "shortcuts":
{
"command": "notebook:clear-cell-output",
"keys": [
"Shift D",
"Shift D"
],
"selector": ".jp-Notebook:focus"
}
And save it! (Ctrl + S)
Then when you are in the editor, just press Esc to escape the edit mode and press Shift + d + d.
Upvotes: 3
Reputation: 51
Go to Help
-> Edit Keyboard Shortcuts
.
Then add the Shortcut you desire to the "Clear Cell" field.
Upvotes: 5
Reputation: 1509
This is not a keyboard shortcut but to clear all output you can click the following buttons:
Upvotes: 1
Reputation: 21
You can do this via the command line:
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace *.ipynb
Upvotes: 1
Reputation: 10003
I just looked and found cell|all output|clear which worked with:
Server Information: You are using Jupyter notebook.
The version of the notebook server is: 6.1.5 The server is running on this version of Python: Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]
Current Kernel Information: Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
Upvotes: 0
Reputation: 10080
Depends if you consider the command palette a short-cut. I do.
Upvotes: 4
Reputation: 1177
You can setup your own shortcut in the UI (for the latest master version):
This menu can be found in Help > Keyboard Shortcuts
in any open notebook.
Upvotes: 102
Reputation: 3275
Add following at start of cell and run it:
from IPython.display import clear_output
clear_output(wait=True)
Upvotes: 21
Reputation: 3990
For versions less than 5:
Change the cell type to raw then back to code: EscRY will discard the output.
For this, you need to edit the custom.js
file which is typically located at ~/.jupyter/custom/custom.js
(if it doesn't exist, create it).
In there, you have to add
require(['base/js/namespace']) {
// setup 'ctrl-l' as shortcut for clearing current output
Jupyter.keyboard_manager.command_shortcuts
.add_shortcut('ctrl-l', 'jupyter-notebook:clear-cell-output');
}
You can add shortcut there for all the fancy things you like, since the 2nd argument can be a function (docs)
If you want mappings for other standard commands, you can dump a list of all available commands by running the following in your notebook:
from IPython.core.display import Javascript
js = """
var jc_html = "";
var jc_array = Object.keys(IPython.notebook.keyboard_manager.command_shortcuts.actions._actions);
for (var i=0;i<jc_array.length;i++) {
jc_html = jc_html + jc_array[i] + "<br >";
}
element.html(jc_html);
"""
Javascript(data=js, lib=None, css=None)
Upvotes: 78