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

支持该特性吗?


当前回答

只需按ctrl + shift + p,然后输入'fold'。 将显示所有关于(un)fold的键绑定。 如果ctrl k不起作用,可能是因为vim扩展覆盖了键。 在这种情况下,您应该修改设置。Json(按CTRL + shift + p,然后键入'settings')

"vim.handleKeys": {
  "<C-k>": false,
},

其他回答

这个特性现在可以在标准版本中使用。为了使折叠/展开控件出现,你需要将鼠标移到行号右侧的区域,如下面的截图所示:

折叠/展开当前块使用(ctrl+k)+(ctrl+l)

注意:这些快捷方式只有在编辑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"
    },

从版本1.3.1(2016-07-17)开始,块崩溃变得更加方便。

任何后跟缩进的行都将有一个'-'字符以允许折叠。如果该块被折叠,那么它将被一个'+'字符所取代,该字符将打开折叠的块。

(Ctrl + Shift + Alt +])仍然会影响所有方块,关闭一层。每重复使用一次,就会关闭一层。Ctrl + Shift + Alt +[)的作用正好相反。

万岁,区块崩溃终于有用了。

自Visual Studio Code版本0.10.11以来,折叠功能已经推出并实现。有以下快捷键可用:

Fold在光标处折叠最里面的未折叠区域: 在Windows和Linux上按Ctrl + Shift + [ macOS上的` ` ` ` ` ` ` ` ` ` ` ` ` 展开光标处的折叠区域: 在Windows和Linux中使用Ctrl + Shift +] macOS上的` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` 折叠编辑器中的所有区域: 在Windows和Linux中,Ctrl + K, Ctrl + 0(零) 在macOS上⌘+ K,⌘+0(零) 展开全部在编辑器中展开所有区域: Windows和Linux下的Ctrl + K, Ctrl + J 在macOS上⌘+ K,⌘+ J


引用:https://code.visualstudio.com/docs/getstarted/keybindings