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

本文讨论如何在Visual Studio Code中实现类似Visual Studio Professional的折叠所有方法的功能。提供了多种快捷键方案,包括Ctrl + K Ctrl + 0进行全部折叠,以及通过右键菜单选择"格式文档"来折叠方法。此外,还提到了使用Ctrl + Shift + P搜索"全部折叠"命令以及使用Ctrl + K,Ctrl + 1和Ctrl + K,Ctrl + 2来折叠不同级别的元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自: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. 您甚至可能会发现跳过第一个命令很有用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值