如何在Visual Studio代码中折叠或折叠代码节?

支持该特性吗?


当前回答

命令K +命令0无效。

其他回答

命令K +命令0无效。

V1.42对折叠的外观和功能进行了一些很好的改进。见https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_42.md # folded-range-highlighting:

折叠范围高亮显示 由于背景色,折叠范围现在更容易发现 对于所有折叠范围。

主题:深色+ 该功能由设置编辑器控制。foldingHighlight和 颜色可以用color editor.foldBackground定制。 “工作台。colorCustomizations ": { “编辑器。foldBackground": "#355000"} 折叠细化 Shift +点击折叠指示器,首先只折叠内层 范围。Shift +再次点击(当所有内层范围都已经折叠时) 也会折叠父元素。Shift +点击再次展开全部。

当对已经折叠的文件使用折叠命令(kb(editor.fold))]时 范围,下一个展开的父范围将被折叠。

使用JavaScript:

//#region REGION_NAME
   ...code here
//#endregion

下面是VSCode中最常用的默认键映射。你可以很容易地自定义他们与你自己的键图。CTRL + K,然后:

Fold All: CTRL + 0

Unfold All: CTRL + J

Fold Region: CTRL + [

Unfold Region: CTRL + ]

Fold Level 1: CTRL+ 1

Fold Level 2: CTRL+ 2

Fold Level 3: CTRL+ 3

Fold Level 1: CTRL+ 4

注意:这些快捷方式只有在编辑keybindings.json时才能正常工作

我不喜欢默认的快捷方式,我想让他们工作如下:

折叠:Ctrl + Alt +] 使用Ctrl + Shift + Alt + 全部折叠:Ctrl + k然后Ctrl +] 展开:Ctrl + Alt + [ 用Ctrl + Shift + Alt + [ 全部展开:Ctrl + k然后Ctrl + [

设置方法:

打开快捷键(JSON) (Ctrl + Shift + p) 将以下代码片段添加到该文件中 已经为折叠/展开自定义键绑定?然后你需要更换它们。

    {
        "key": "ctrl+alt+]",
        "command": "editor.fold",
        "when": "editorTextFocus && foldingEnabled"
    },
    {
        "key": "ctrl+alt+[",
        "command": "editor.unfold",
        "when": "editorTextFocus && foldingEnabled"
    },
    {
        "key": "ctrl+shift+alt+]",
        "command": "editor.foldRecursively",
        "when": "editorTextFocus && foldingEnabled"
    },
    {
        "key": "ctrl+shift+alt+[",
        "command": "editor.unfoldRecursively",
        "when": "editorTextFocus && foldingEnabled"
    },
    {
        "key": "ctrl+k ctrl+[",
        "command": "editor.unfoldAll",
        "when": "editorTextFocus && foldingEnabled"
    },
    {
        "key": "ctrl+k ctrl+]",
        "command": "editor.foldAll",
        "when": "editorTextFocus && foldingEnabled"
    },