如何在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"
},
其他回答
我希望Visual Studio Code可以处理:
#region Function Write-Log
Function Write-Log {
...
}
#endregion Function Write-Log
现在Visual Studio Code只是忽略它,不会折叠它。 与此同时,notepad++和PowerGUI可以很好地处理这个问题。
更新:我刚刚注意到Visual Studio Code的更新。现在支持了!
自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
默认的折叠/扩展快捷方式是:
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"
},
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))]时 范围,下一个展开的父范围将被折叠。
折叠/展开当前块使用(ctrl+k)+(ctrl+l)