java IntelliJ IDEA - 折叠 for 循环和/或 if/else 语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36635018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ IDEA - Fold for loop and/or if/else statements
提问by PhotonicPizza
I'd love to have a way of IntelliJ letting me fold for
loops and if/else
statements. But, I can't seem to find a way to do it automatically. I know you can use the //region
and //endregion
comments, or that you can do it manually with Ctrl+Shift+period, but is there a way to avoid all that and have it fold like methods or classes, without doing all that other stuff?
我很想有一种 IntelliJ 方法让我折叠for
循环和if/else
语句。但是,我似乎无法找到自动执行此操作的方法。我知道您可以使用//region
和//endregion
注释,或者您可以使用 Ctrl+Shift+句点手动完成,但是有没有办法避免所有这些并使其像方法或类一样折叠,而无需执行所有其他操作?
回答by zhuguowei
You can fold and unfold:
Code blocks, i.e. code fragments surrounded by a matched pair of curly braces
{}
.To collapse a code block, place the cursor within that block and then select Code | Folding | Fold Code Blockor press ?+?+.(mac) or ctrl+?+.(Linux / Windows).
NoteCode folding works for the keywords
if
/while
/else
/for
/try
/except
/finally
/with
in case of at least two statements.
您可以折叠和展开:
代码块,即由一对匹配的花括号包围的代码片段
{}
。要折叠代码块,请将光标置于该块内,然后选择代码 | 折叠 | 折叠代码块或按?+ ?+ .(mac) 或ctrl+ ?+ .(Linux / Windows)。
需要注意的关键字代码折叠的作品
if
/while
/else
/for
/try
/except
/finally
/with
在至少两个语句的情况。
See: https://www.jetbrains.com/help/idea/2016.3/code-folding.html
参见:https: //www.jetbrains.com/help/idea/2016.3/code-folding.html
回答by Makoto
Under Editor > General > Code Folding, you can enable this functionality expressly.
在 Editor > General > Code Folding 下,您可以明确启用此功能。
By default, if you wish for it to collapse method bodies, you can tick that selection. There are a lot of other options available, which should cover your needs.
默认情况下,如果您希望它折叠方法主体,您可以勾选该选项。还有很多其他选项可用,它们应该可以满足您的需求。
If there's something that isn't covered, you can always enable "Show code folding outline" and use that to fold certain elements, although loops aren't foldable.
如果有未涵盖的内容,您始终可以启用“显示代码折叠轮廓”并使用它来折叠某些元素,尽管循环不可折叠。
回答by Cuneyt
Put the cursor anywhere in the line of method definition for which you want the code fragments to be folded and press ctrl+shift+- this will collapse the whole method and press ctrl++ right after. this will keep the if and for loop fragments inside the method collapsed (intellij 2020.1.1 linux)
将光标放在您希望折叠代码片段的方法定义行中的任何位置,然后按 ctrl+shift+- 这将折叠整个方法,然后立即按 ctrl++。这将使方法内的 if 和 for 循环片段保持折叠状态(intellij 2020.1.1 linux)