如何折叠Visual Studio Code for Windows中的代码部分?

本文翻译自:How do I collapse sections of code in Visual Studio Code for Windows?

How do I fold or collapse sections of code in Visual Studio Code? 如何在Visual Studio Code中折叠或折叠代码段?

Is this feature supported? 是否支持此功能?


#1楼

参考:https://stackoom.com/question/229zz/如何折叠Visual-Studio-Code-for-Windows中的代码部分


#2楼

Folding has been rolled out and is now implemented since Visual Studio Code version 0.10.11 . 自Visual Studio Code 0.10.11版以来, 折叠已被推广,现已实现。 There are these keyboard shortcuts available: 这些键盘快捷键可用:

  • Fold folds the innermost uncollapsed region at the cursor: Fold在光标处折叠最里面的未折叠区域:

    • Ctrl + Shift + [ on Windows and Linux Ctrl + Shift + [在Windows和Linux上
    • + + [ on macOS mac + + [在macOS上
  • Unfold unfolds the collapsed region at the cursor: 展开展开光标处的折叠区域:

    • Ctrl + Shift + ] on Windows and Linux 在Windows和Linux上为Ctrl + Shift + ]
    • + + ] on macOS OS + + ]在macOS上
  • Fold All folds all regions in the editor: Fold All折叠编辑器中的所有区域:

    • Ctrl + ( K => 0 ) (zero) on Windows and Linux 在Windows和Linux上为Ctrl +( K => 0 )(零)
    • + ( K => 0 ) (zero) on macOS mac +( K => 0 )(零)在macOS上
  • Unfold All unfolds all regions in the editor: 全部展开将在编辑器中展开所有区域:

    • Ctrl + ( K => J ) on Windows and Linux 在Windows和Linux上为Ctrl +( K => J
    • + ( K => J ) on macOS mac +( K => J )在macOS上

References: https://code.visualstudio.com/docs/getstarted/keybindings 参考: https : //code.visualstudio.com/docs/getstarted/keybindings


#3楼

The default shortcut for collapse/extend are: 折叠/扩展的默认快捷方式是:

Ctrl + Shift + [ : "Fold" Ctrl + Shift + [ :“折叠”

Ctrl + Shift + Alt + [ : "Fold all" Ctrl + Shift + Alt + [ :“全部折叠”

Ctrl + Shift + ] : "Unfold" Ctrl + Shift + ] :“展开”

Ctrl + Shift + Alt + ] : "Unfold all" Ctrl + Shift + Alt + ] :“全部展开”

Or go to keybindings.json and change as you wish. 或转到keybindings.json并根据需要进行更改。

For example: 例如:

{
    "key": "cmd+k cmd+m",
    "command": "editor.foldAll",
    "when": "editorFocus"
},
{
    "key": "cmd+m cmd+k",
    "command": "editor.unfoldAll",
    "when": "editorFocus"
},

#4楼

Collapsing is now supported in release 1.0 : 发行版1.0现在支持折叠:

Source Code Folding Shortcuts 源代码折叠快捷方式

There are new folding actions to collapse source code regions based on their folding level. 有一些新的折叠动作可以根据源代码区域的折叠级别折叠它们。

There are actions to fold level 1 ( Ctrl + K Ctrl + 1 ) to level 5 ( Ctrl + K Ctrl + 5 ). 有一些操作可以将级别1( Ctrl + K Ctrl + 1 )折叠到级别5( Ctrl + K Ctrl + 5 )。 To unfold, use Unfold All ( Ctrl + Shift + Alt + ] ). 要展开,请使用全部展开( Ctrl + Shift + Alt + ] )。

The level folding actions do not apply to region containing the current cursor. 级别折叠操作不适用于包含当前光标的区域。

I had a problem finding the ] button on my keyboard (Norwegian layout), and in my case it was the Å button. 我在键盘上找到[ ]按钮(挪威布局)时遇到问题,在我的情况下是Å按钮。 (Or two buttons left and one down starting from the backspace button.) (或者从退格按钮开始,向左两个按钮,向下一个按钮。)


#5楼

As of Visual Studio Code version 1.12.0, April 2017, see Basic Editing > Folding section in the docs. 从2017年4月的Visual Studio Code 1.12.0版开始,请参阅文档中的基本编辑>折叠部分。

The default keys are: 默认密钥为:

Fold All: CTRL + K , CTRL + 0 (zero) 全部折叠: CTRL + KCTRL + 0 (零)

Fold Level [n]: CTRL + K , CTRL + [n] * 折叠等级[n]: CTRL + KCTRL + [n] *

Unfold All: CTRL + K , CTRL + J 全部展开: CTRL + KCTRL + J

Fold Region: CTRL + K , CTRL + [ 折叠区域: CTRL + KCTRL + [

Unfold Region: CTRL + K , CTRL + ] 展开区域: CTRL + KCTRL + ]

*Fold Level: to fold all but the most outer classes, try CTRL + K , CTRL + 1 *折叠级别:要折叠除最外面的类以外的所有类,请尝试按CTRL + KCTRL + 1

Macs: use instead of CTRL (thanks Prajeet) Mac:使用而不是CTRL (感谢Prajeet)


#6楼

As of version 1.3.1 (2016-07-17), Block Collapse is much more convenient. 从1.3.1版(2016-07-17)开始,块折叠更加方便。

Any line followed by an indented line will have a '-' character to allow collapse. 紧随其后的任何行都将带有“-”字符以允许折叠。 If the block is collapsed, it will then be replaced by a '+' character that will open the collapsed block. 如果该块是折叠的,则将替换为“ +”字符,这将打开折叠的块。

The ( Ctrl + Shift + Alt + ] ) will still affect all blocks, closing one level. Ctrl + Shift + Alt + ] )仍会影响所有块,关闭一个级别。 Each repeated use closed one more level. 每次重复使用将关闭一个级别。 The ( Ctrl + Shift + Alt + [ ) works in the opposite way. Ctrl + Shift + Alt + [ )以相反的方式工作。

Hooray, block collapse finally works usefully. 万岁,方块坍塌终于有用了。

发布了0 篇原创文章 · 获赞 8 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/asdfgh0077/article/details/105559730