IntelliJ (in my case with Kotlin) has a code style property Function declaration parameters set to Chop down if long by default. This is just what I want, but sometimes I also want to do that manually (not only when formating if it's too long). Is there a shortcut or a way to set one in the IDE?
fun foo(p1: T1, p2: T2) {
...
}
becomes
fun foo(
p1: T1,
p2: T2,
) {
...
}
The best would be if there was a shortcut similar to folding/expanding code segments, that also work for example on Array declaration.
[1, 2, 3, 4]
becomes
[
1,
2,
3,
4,
]
I couldn't find any suitable action, maybe I searched for the wrong terms.
Put your cursor on the parameter list, and Option+Enter (on macOS) or Alt+Enter (on Windows). This brings up a context menu like this:

This is known as Context Actions. You should select "Put parameters on separate lines".
This also works for argument lists when you are calling a method, so you can use this for things like arrayOf:

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