How to collapse the code part in Visual Studio Code for Windows?

This article was translated from: 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? How do I fold or collapse sections of code in Visual Studio Code ?

Is this feature supported? Is this feature supported ?


#1st Floor

Reference: https://stackoom.com/question/229zz/ How to collapse the code section in Visual-Studio-Code-for-Windows


#2nd Floor

Folding has been rolled out and is now implemented since Visual Studio Code version 0.10.11 . Since Visual Studio Code 0.10.11 version , folding has been promoted and has now been achieved. There are these keyboard shortcuts available: These keyboard shortcuts are available:

  • Fold Folds The AT Innermost uncollapsed The Cursor Region: Fold not folded region at the cursor innermost fold:

    • Ctrl+ Shift+ [on Windows and Linux Ctrl+ Shift+ [on Windows and Linux
    • + + [on macOS mac+ + [on macOS
  • Unfold unfolds the collapsed region at the cursor: Expand the collapsed area at the cursor :

    • Ctrl+ Shift+ ]ON Windows and Linux on Windows and Linux Ctrl+ Shift+]
    • + + ]on macOS OS+ + ]on macOS
  • All Fold Folds in All Regions The Editor: Fold All folding editor for all regions:

    • Ctrl+ ( K=> 0) (ZERO) ON Windows and Linux on Windows and Linux Ctrl+ ( K=> 0) (zero)
    • + ( K=> 0) (zero) on macOS mac+ ( K=> 0) (zero) on macOS
  • Unfold All unfolds all regions in the editor: Expand all will expand all regions in the editor :

    • Ctrl+ ( K=> J) ON Windows and Linux on Windows and Linux Ctrl+ ( K=> J)
    • + ( K=> J) on macOS mac+ ( K=> J) on macOS

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


#3rd floor

The default shortcut for collapse / extend are: The default shortcut for collapse / extend are :

Ctrl+ Shift+ [: "Fold" Ctrl+ Shift+ [: "Fold"

Ctrl+ Shift+ Alt+ [: "All Fold" Ctrl+ Shift+ Alt+ [: "Collapse"

Ctrl+ Shift+ ]: "Unfold" Ctrl+ Shift+ ]: "Unfold"

Ctrl+ Shift+ Alt+ ]: "Unfold All" Ctrl+ Shift+ Alt+ ]: "Expand All"

Or go to keybindings.json and change as you wish. Or go to keybindings.json and make changes as needed.

For example: For example:

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

#4th floor

Collapsing is now supported in release 1.0 : The release 1.0 now supports folding:

Source Code Folding Shortcuts source code folding shortcut

There are new folding actions to collapse source code regions based on their folding level. There are new folding actions to collapse source code regions based on their folding level .

Actions are to fold Level there 1 ( Ctrl+ K Ctrl+ 1) to Level 5 ( Ctrl+ K Ctrl+ 5). There are some operations may be level 1 ( Ctrl+ K Ctrl+ 1) is folded to level 5 ( Ctrl+ K Ctrl+ 5). To unfold, use Unfold All ( Ctrl+ Shift+ Alt+ ]). To expand, use unfold all ( Ctrl+ Shift+ Alt+ ]).

The level folding actions do not apply to region containing the current cursor. 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. I ]encountered a problem when I found the [ button (Norwegian layout) on the keyboard Å , in my case it was a button. (Or two buttons left and one down starting from the backspace button.) (Or from the backspace button, two buttons to the left and one button to the next.)


#5th Floor

As of Visual Studio Code version 1.12.0, April 2017, see Basic Editing> Folding section in the docs. Starting with Visual Studio Code version 1.12.0 in April 2017 , please refer to the Basic Editing> Collapse section in the document .

The default keys are: The default keys are :

Fold All: CTRL+ K, CTRL+ 0(zero) Fold all: CTRL+ K, CTRL+ 0(zero)

Fold Level [n]: CTRL+ K, CTRL+ [n]* Fold Level [n]: CTRL+ K, CTRL+ [n]*

Unfold All: CTRL+ K, CTRL+ J Expand all: CTRL+ K, CTRL+J

Region Fold: CTRL+ K, CTRL+ [ folding area: CTRL+ K, CTRL+[

Region Unfold: CTRL+ K, CTRL+ ] expanded area: CTRL+ K, CTRL+]

* Fold Level: to fold all but the most outer classes, try CTRL+ K, CTRL+ * Fold Level: To fold all classes 1 except the outermost class, try pressing CTRL+ K, CTRL+1

MACS: use INSTEAD of CTRL(Thanks Prajeet) Mac: Use instead CTRL(thanks Prajeet)


#6th floor

As of version 1.3.1 (2016-07-17), Block Collapse is much more convenient. Starting from version 1.3.1 (2016-07-17), block folding is more convenient.

Any line followed by an indented line will have a '-' character to allow collapse. Any line immediately following will have a "-" character to allow folding. If the block is collapsed, it will then be replaced by a '+' character that will open the collapsed block. If the block is collapsed, it will be replaced with a "+" character, which will open the collapsed block.

Of The ( Ctrl+ Shift+ Alt+ ]) All Blocks Will Affect Still, the closing Level One. ( Ctrl+ Shift+ Alt+ ]) Will affect all the blocks, a level close. Each repeated use closed one more level. Each repeated use will close one level. At The ( Ctrl+ Shift+ Alt+ [) Works in at The Opposite Way. ( Ctrl+ Shift+ Alt+ [) In the opposite manner.

Hooray, block collapse finally works usefully. Long live , block collapse finally works .

Published 0 original articles · praised 8 · 30,000+ views

Guess you like

Origin blog.csdn.net/asdfgh0077/article/details/105559730