VS Code 编辑 .ipynb 文件:如何折叠笔记本单元格?

VS Code editing .ipynb file: How to collapse notebook cells?

我正在使用 Jupyter Notebook 扩展在 VS Code 中编辑 .ipynb 文件。我似乎不知道如何折叠(或展开)单元格。

有人可以向我解释如何执行此操作(使用热键或不使用热键),或者提供我可能做错的想法吗?

我在三组条件下尝试了下面显示的每个热键:1. 选中单元格输入 left-hand 一侧的蓝色垂直条,2. 蓝色垂直条位于 left-hand 侧left-hand 选择了我的单元格输出的一侧,3. 我的光标在我的单元格输入中。

目前VS Code的Jupyter不支持使用该功能,可以参考这个link:Jupyter notebook cell code folding and output view expanding request.

另外,请尝试使用“Visual Studio Code Insiders”,在Jupyter的单元格中右击,select“Collapse Cell Input”或“Collapse Cell Output”:

之前:

之后:

我使用的是 1.58.2 版,现在可以使用此功能了!

只需右键单击代码单元格,然后 select 'Collapse Cell Output'。

或者,单击代码单元格(确保您处于命令模式)并使用键盘快捷键 ⌘K T(Mac)或 Ctrl-K T(Windows)。

在我的 VSCode 内部构建版本 1.61.0 中,它正在运行。

什么在起作用 ->

 a) One shot expand/collapse all cells(code/output) in '.ipynb'(notebook)
 b) Single cell code/output expand/collapse in '.ipynb'(notebook)
 c) code folding in `.py` file with `#%%` (hierarchy style)
  1. for .ipynb(您的要求)

    有键绑定可用:jupyter.notebookeditor.expandallcells/collapseallcells

    它有什么作用?

            Expands/collapses all cells in one shot
    

    找到这个设置->

         Top menu File->Preferences->Keyboard Shortcuts
         In search("Type to search in keybindings"...top side) 
         type "Notebook Expand" or "Notebook Collapse", check out:
    
                 Notebook: Expand/Collapse All Cells, 
                 Notebook: Expand/Collapse Cell Input and 
                 Notebook: Expand/Collapse Cell Output
    
    
         Its possible to expand/collapse single/all cells with these shortcuts keys.
    

为了使这个回答完整(其他人已经回答)->

    1.  double click gutter area (immediate space on left side of code cell) to Expand/Collapse cell (code/output)

    2.  right click on gutter area to get Expand/Collapse cell (code/output)
  1. “.ipynb”和“.py”的详细 [​​=39=] here

另一种折叠单元格的方法即将推出 v1.64。参见

Cell collapsing UI

Notebook cells have a blue bar on the left side to indicate that they are focused. This bar is now interactive - you can click the top part to collapse the cell input, and the bottom part to collapse the output.