如何在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"
},
其他回答
下面是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
ctrl + k + 0:折叠所有级别(命名空间,类,方法,块)
CTRL + k + 1: namspace
CTRL + k + 2: class
CTRL + k + 3:方法
CTRL + k + 4:方块
CTRL + k + [or]:当前光标块
ctrl + k + j:展开
折叠水平,一键折叠到你想要的水平。
我希望Visual Studio Code可以处理:
#region Function Write-Log
Function Write-Log {
...
}
#endregion Function Write-Log
现在Visual Studio Code只是忽略它,不会折叠它。 与此同时,notepad++和PowerGUI可以很好地处理这个问题。
更新:我刚刚注意到Visual Studio Code的更新。现在支持了!
如果任何快捷键都不起作用(就像对我来说),作为一种变通方法,你也可以打开命令面板(Ctrl + 3或View ->命令面板…)并键入折叠全部: