Keyboard shortcut to clear cell output in Jupyter notebook

后端 未结 6 1666
误落风尘
误落风尘 2020-12-07 15:49

Does anyone know what is the keyboard shortcut to clear (not toggle) the cell output in Jupyter Notebook?

相关标签:
6条回答
  • 2020-12-07 15:57

    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.

    0 讨论(0)
  • 2020-12-07 16:04

    Add following at start of cell and run it:

    from IPython.display import clear_output
    clear_output(wait=True)
    
    0 讨论(0)
  • 2020-12-07 16:08

    Just adding in for JupyterLab users. Ctrl, (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"
            }
        ]
    }
    
    0 讨论(0)
  • 2020-12-07 16:13

    STEP 1 :Click on the "Help"and click on "Edit Keyboard Shortcut" STEP1-screenshot

    STEP 2 :Add the Shortcut you desire to the "Clear Cell" field STEP2-screenshot

    0 讨论(0)
  • 2020-12-07 16:17

    For versions less than 5:

    Option 1 -- quick hack:

    Change the cell type to raw then back to code: EscRY will discard the output.

    Option 2 -- custom shortcut (without GUI):

    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)
    
    0 讨论(0)
  • 2020-12-07 16:19

    Depends if you consider the command palette a short-cut. I do.

    1. Press 'control-shift-p', that opens the command palette.
    2. Then type 'clear cell output'. That will let you select the command to clear the output.

    0 讨论(0)
提交回复
热议问题