如何在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 +[: "折叠"
按下Ctrl + Shift + Alt +[:“全部折叠”
Ctrl + Shift +]:“展开”
按下Ctrl + Shift + Alt +]:“全部展开”
或者去键绑定。Json和更改,如你所愿。
例如:
{
"key": "cmd+k cmd+m",
"command": "editor.foldAll",
"when": "editorFocus"
},
{
"key": "cmd+m cmd+k",
"command": "editor.unfoldAll",
"when": "editorFocus"
},
命令K +命令0无效。
你应该添加用户设置:
{
"editor.showFoldingControls": "always",
"editor.folding": true,
"editor.foldingStrategy": "indentation",
}
从2017年4月Visual Studio Code 1.12.0版本开始,请参阅文档中的基本编辑>折叠部分。
默认键为:
全部折叠:CTRL+K, CTRL+0 (0) 折叠等级[n]: CTRL+K, CTRL+[n]* 展开全部:CTRL+K, CTRL+J 折叠区域:CTRL+K, CTRL+[ 展开区域:CTRL+K, CTRL+]
*折叠级别:折叠所有,但最外层的类,尝试CTRL+K, CTRL+1
mac:使用⌘而不是CTRL(感谢Prajeet)