Is there syntax just like #region #endregion in Kotlin?

Solution 1:

In IntelliJ IDEA (or Android Studio): yes, you can. You can do it by using //region and //endregion comments or by using //<editor-fold desc="..."> and //</editor-fold>.

Example:

//region name

fun someCode() { ... }
fun someMoreCode() { ... }

//endregion

// or

//<editor-fold desc="name">

fun someCode() { ... }
fun someMoreCode() { ... }

//</editor-fold>

Solution 2:

There are more supported styles (https://www.jetbrains.com/help/idea/code-folding.html#supported_comments)

The Netbeans Style

//<editor-fold desc="YOUR REGION NAME">
fun main(vararg args: String) { ... }
...
//</editor-fold>

or the visual studio style

//region YOUR REGION NAME
fun main(vararg args: String) { ... }
...
//endregion

They can be collapsed and expanded in IntelliJ. When it's collapsed, only the description is displayed.