Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

declare a block of code using comments in intellij with ability to collapse

I have a bunch of code like this:

// methods related to Provider X
public void methodA() {...}
public String someOtherMethod {...}
public void increaseRankOfProviderX {...}
// end of 'methods related to Provider X'

I want IntelliJ to know this part as a block and I also want to collapse them, is there a way or plugin available I can achieve this in IntelliJ?

like image 562
Seyed Ali Roshan Avatar asked Oct 18 '25 14:10

Seyed Ali Roshan


1 Answers

Official documentation.

Two ways you can fold the code in IntelliJ IDEA:

NetBeans-like:

//<editor-fold desc="...">
... code ...
//</editor-fold>

VisualStudio-like:

//region <...>
... code ...
//endregion

Note that line commenting symbols for "region...endregion" can be changed from "//" to "#" if the '#' character is supported by a language. But by default custom folding comments use the same comment characters as normally used for language line comments.

Instead of typing the comments manually, in many cases you can invoke a 'Surround With' action for the highlighted code with Ctrl+Alt+T:

enter image description here

like image 177
Koyasha Avatar answered Oct 22 '25 00:10

Koyasha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!