3

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

有人可以向我解释如何做到这一点(使用热键或不使用热键),或者就我可能做错的事情给出想法吗?

我在三组条件下尝试了下面显示的每个热键:1. 选中单元格输入左侧的蓝色竖条,2. 单元格左侧的蓝色竖条选择输出,3. 将光标放在单元格输入中。

4

4 回答 4

4

目前,VS Code 的 Jupyter 不支持使用该功能,可以参考这个链接:Jupyter notebook cell code fold and output view expansion request

另外,请尝试使用“ Visual Studio Code Insiders ”,在 Jupyter 的单元格中单击鼠标右键,然后选择“ Collapse Cell Input”或“ Collapse Cell Output”:

前:

在此处输入图像描述

后:

在此处输入图像描述

于 2021-04-01T03:21:35.087 回答
3

在我的 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. 对于.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' 的详细帖子在这里
于 2021-09-04T03:03:12.730 回答
2

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

只需右键单击代码单元格并选择“折叠单元格输出”。

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

折叠单元格输出

于 2021-07-30T13:18:23.140 回答
1

另一种折叠单元格的方法即将发布到 v1.64。看

单元格折叠 UI

笔记本单元格的左侧有一个蓝色条,表示它们已聚焦。此栏现在是交互式的 - 您可以单击顶部折叠单元格输入,单击底部折叠输出。

细胞崩溃演示

于 2022-01-29T04:57:46.173 回答