折叠Visual Studio代码中的所有方法

本文翻译自:Collapse all methods in Visual Studio Code

In Visual Studio Professional, we have a shortcut key, Ctrl + M Ctrl + O to collapse all methods and properties in a class. 在Visual Studio Professional中,我们有一个快捷键Ctrl + M Ctrl + O来折叠类中的所有方法和属性。 How can I do a similar thing in Visual Studio Code? 如何在Visual Studio Code中执行类似的操作?

I know there are shortcut keys like Ctrl + Shift + [ , but this does not meet the needs. 我知道有快捷键,如Ctrl + Shift + [ ,但这不符合需要。

Is it possible to get the Visual Studio Professional-like behaviour in Visual Studio Code? 是否有可能在Visual Studio代码中获得类似Visual Studio Professional的行为?


#1楼

参考:https://stackoom.com/question/2SZZk/折叠Visual-Studio代码中的所有方法


#2楼

Like this ? 像这样 ? (Visual Studio Code version 0.10.11) (Visual Studio代码版本0.10.11)

Fold All ( Ctrl + K Ctrl + 0 ) 全部折叠( Ctrl + K Ctrl + 0

Unfold All ( Ctrl + K Ctrl + J ) 展开全部( Ctrl + K Ctrl + J

Fold Level n ( Ctrl + K Ctrl + N ) 折叠等级n( Ctrl + K Ctrl + N


#3楼

To collapse methods in the Visual Studio Code editor: 要折叠Visual Studio代码编辑器中的方法:

  1. Right-click anywhere in document and select "format document" option. 右键单击文档中的任意位置,然后选择“格式文档”选项。
  2. Then hover next to number lines and you will see the (-) sign for collapsing method. 然后将鼠标悬停在数字行旁边,您将看到折叠方法的( - )符号。

NB.: As per the Visual Studio Code documentation, a folding region starts when a line has a smaller indent than one or more following lines, and ends when there is a line with the same or smaller indent. 注意:根据Visual Studio Code文档,折叠区域在一条线的缩进比一条或多条跟随线更小时开始,并在有一条线条具有相同或更小的缩进时结束。


#4楼

  • Fold All: 全部折叠:

    • Windows: Ctrl + k + 0 Windows: Ctrl + k + 0
    • Mac: + k + 0 Mac: + k + 0
  • Unfold All: 展开全部:

    • Windows: Ctrl + k + j Windows: Ctrl + k + j
    • Mac: + k + j Mac: + k + j

To see all the shortcuts in the editor in Mac, just type: + k + s 要查看Mac中编辑器中的所有快捷方式,只需输入: + k + s即可

折叠Visual Studio代码中的所有方法

All shortcuts kept up to date by the Visual Studio Code team: Visual Studio Code Shortcuts 所有快捷方式都由​​Visual Studio代码团队保持最新: Visual Studio代码快捷方式


#5楼

The beauty of Visual Studio Code is Visual Studio Code的美妙之处在于

Ctrl + Shift + P Ctrl + Shift + P.

Hit it and search anything you want. 点击它并搜索你想要的任何东西。

In your case, hit Ctrl + Shift + P and type fold all . 在您的情况下, 按Ctrl + Shift + P并键入全部折叠


#6楼

Ctrl + K , Ctrl + 1 and then Ctrl + K , Ctrl + 2 will do close to what you want. 按Ctrl + KCtrl + 1然后按Ctrl + KCtrl + 2将接近你想要的。

The first command collapses level 1 (usually classes), and the second command collapses level 2 (usually methods). 第一个命令折叠级别1(通常是类),第二个命令折叠级别2(通常是方法)。

You might even find it useful to skip the first command. 您甚至可能会发现跳过第一个命令很有用。