简体   繁体   English

JetBrains / IntelliJ 用于折叠所有方法的键盘快捷键

[英]JetBrains / IntelliJ keyboard shortcut to collapse all methods

I'm working on some legacy code that has a class that is 10,000+ lines of code and has 100s of methods.我正在处理一些遗留代码,它的类有 10,000 多行代码和 100 多种方法。 Is there a shortcut for any JetBrains IDE (since the shortcut would likely be shared across all of them) to collapse all the methods / functions so that only the method signatures are shown?是否有任何 JetBrains IDE 的快捷方式(因为快捷方式可能会在所有这些 IDE 之间共享)来折叠所有方法/函数,以便仅显示方法签名?

Something like this:像这样的东西:

public String myMethod(String arg1, int arg2){...}

public String mySecondMethod(String arg1, int arg2){...}

You may take a look at intellij code folding shortcuts .您可以查看intellij 代码折叠快捷方式

For Windows/Linux do: Ctrl + Shift + -对于 Windows/Linux 执行: Ctrl + Shift + -

For mac use Command + Shift + -对于 mac 使用Command + Shift + -

To unfold again do Ctrl + Shift + + or Command + Shift + + respectivley.要再次展开,请分别按 Ctrl + Shift + +Command + Shift + +

The above suggestion of Ctrl + Shift + - code folds all code blocks recursively.上面Ctrl + Shift + -代码的建议递归折叠所有代码块。 I only wanted to fold the methods for my classes.我只想折叠我的课程的方法。

Code > Folding > Expand all to level > 1 Code > Folding > Expand all to level > 1

I managed to achieve this by using the menu option Code > Folding > Expand all to level > 1 .我设法通过使用菜单选项Code > Folding > Expand all to level > 1来实现这一点。

I re-assigned it to Ctrl + NumPad-1 which gives me a quick way to collapse my classes down to their methods.我将它重新分配给Ctrl + NumPad-1 ,这使我可以快速将我的类折叠为它们的方法。

This works at the 'block level' of the file and assumes that you have classes defined at the top level of your file, which works for code such as PHP but not for JavaScript (nested closures etc.)这适用于文件的“块级别”,并假设您在文件的顶层定义了类,该类适用于 PHP 等代码,但不适用于 JavaScript(嵌套闭包等)。

转到菜单选项代码 > 折叠以访问所有代码折叠相关选项及其快捷方式。

@precastic's answer above is, imo, the right idea. @precastic 上面的答案是,imo,正确的想法。

Worth noting that in IDEA 2018.2 (and surely other nearby versions) there are default keyboard shortcuts for this: (showing Mac, see Code > Folding > Expand All to Level for your system):值得注意的是,在 IDEA 2018.2(当然还有附近的其他版本)中,有默认的键盘快捷键:(显示 Mac,请参阅代码 > 折叠 > 全部展开到系统级别):

Cmd + Option + Keypad * , 1 - expand all to level 1 Cmd + Option + Keypad * , 1 - 全部扩展到级别 1
Cmd + Option + Keypad * , 2 - expand all to level 2 Cmd + Option + Keypad * , 2 - 全部扩展到第 2 级
... ...
Cmd + Option + Keypad * , 5 - expand all to level 5 Cmd + Option + Keypad * , 5 - 全部扩展到第 5 级

Note: these are "second stroke" shortcuts.注意:这些是“第二笔画”快捷方式。 First press Cmd + Option + * , then release, then hit the number you want.先按Cmd + Option + * ,然后松开,然后点击你想要的数字。

您可以转到设置 > 编辑器 > 常规 > 代码折叠并选中“显示代码折叠大纲”。

In Rider, this would be Ctrl + Shift + Keypad * , 2在 Rider 中,这将是Ctrl + Shift + Keypad * , 2

But!, you cannot use the number 2 on keypad , only number 2 on the top row of the keyboard would work.但是!,您不能在键盘上使用数字 2 ,只能使用键盘顶行的数字 2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM