Collapse all methods in Visual Studio Code

我只是一个虾纸丫 提交于 2019-12-03 01:29:13

问题


In Visual Studio Professional, we have a shortcut key, Ctrl + M Ctrl + O to collapse all methods and properties in a class. How can I do a similar thing in Visual Studio Code?

I know there are shortcut keys like Ctrl + Shift + [, but this does not meet the needs.

Is it possible to get the Visual Studio Professional-like behaviour in Visual Studio Code?


回答1:


  • Fold All:

    • Windows: Ctrl + k + 0
    • Mac: + k + 0
  • Unfold All:

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

To see all the shortcuts in the editor in Mac, just type: + k + s

All shortcuts kept up to date by the Visual Studio Code team: Visual Studio Code Shortcuts




回答2:


Like this ? (Visual Studio Code version 0.10.11)

Fold All (Ctrl+K Ctrl+0)

Unfold All (Ctrl+K Ctrl+J)

Fold Level n (Ctrl+K Ctrl+N)




回答3:


  • Ctrl + K + 0: fold all levels (namespace, class, method, and block)
  • Ctrl + K + 1: namspace
  • Ctrl + K + 2: class
  • Ctrl + K + 3: methods
  • Ctrl + K + 4: blocks
  • Ctrl + K + [ or Ctrl + k + ]: current cursor block
  • Ctrl + K + j: UnFold



回答4:


The beauty of Visual Studio Code is

Ctrl + Shift + P

Hit it and search anything you want.

In your case, hit Ctrl + Shift + P and type fold all.




回答5:


Ctrl+K, Ctrl+1 and then Ctrl+K, Ctrl+2 will do close to what you want.

The first command collapses level 1 (usually classes), and the second command collapses level 2 (usually methods).

You might even find it useful to skip the first command.




回答6:


Mac Users

Fold Commands

Unfold commands




回答7:


Collapse All is Fold All in Visual Studio Code.

Press Ctrl + K + S for All Settings. Assign a key which you want for Fold All. By default it's Ctrl + K + 0.




回答8:


Use Ctrl + K + 0 to fold all and Ctrl + K + J to unfold all.




回答9:


You should add user settings:

{
    "editor.showFoldingControls": "always",
    "editor.folding": true,
    "editor.foldingStrategy": "indentation", 
}



回答10:


To collapse methods in the Visual Studio Code editor:

  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.




回答11:


I recently made an extension for collapsing C# code to definitions since I was also missing that feature from Visual Studio. Just look for "Fold to Definitions" and you should find it, or just follow this link.

The repository is public, so you can easily inspect the extension.ts file and adapt it to other languages. It is nowhere near perfect, but it does the job. It uses regular expressions to find methods, properties, and classes, and then moves the selection to those lines and executes a fold command.



来源:https://stackoverflow.com/questions/42660670/collapse-all-methods-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!