如何在Visual Studio代码中折叠或折叠代码节?
支持该特性吗?
如何在Visual Studio代码中折叠或折叠代码节?
支持该特性吗?
当前回答
注意:这些快捷方式只有在编辑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"
},
其他回答
折叠水平,一键折叠到你想要的水平。
这是用于折叠和展开代码的最新内置(默认)键盘快捷键
键盘快捷键
Ctrl+Shift+[ Fold (collapse) region
Ctrl+Shift+] Unfold (uncollapse) region
Ctrl+K Ctrl+[ Fold (collapse) all subregions
Ctrl+K Ctrl+] Unfold (uncollapse) all subregions
Ctrl+K Ctrl+0 Fold (collapse) all regions
Ctrl+K Ctrl+J Unfold (uncollapse) all
注意:但在某些情况下,你的vs code扩展或用户将改变键盘绑定(快捷键)。所以最好的选择是这样的
view->命令面板OR cntrl+shift+p . view->命令面板 输入“fold”,它会提示折叠和展开以及快捷方式。您可以键入快捷方式,而不是命令面板
eg:
折叠所有
展开所有
只需按ctrl + shift + p,然后输入'fold'。 将显示所有关于(un)fold的键绑定。 如果ctrl k不起作用,可能是因为vim扩展覆盖了键。 在这种情况下,您应该修改设置。Json(按CTRL + shift + p,然后键入'settings')
"vim.handleKeys": {
"<C-k>": false,
},
使用JavaScript:
//#region REGION_NAME
...code here
//#endregion
折叠/展开当前块使用(ctrl+k)+(ctrl+l)