antikantian antikantian - 1 month ago 8
Scala Question

How to specify indentations on multiline parameter lists in IntelliJ Scala?

This has been bothering me for a while, but I can't seem to figure out how to change this formatting. Let's take a case class as an example:

How I like my code formatted

I prefer two tabs after a line-continuation; however, IntelliJ seems to force this style:

How IntelliJ wants to format code

This behavior seems to be controlled by

Preferences -> Editor -> Code Style -> Scala -> Other -> Alternate indentation for constructor args and parameter declarations
, which specifies a minimum of 0 spaces, and that simply brings the arg list inline with the opening parentheses. This isn't a big deal by itself, but whenever I copy/paste blocks of code, it reformats everything and I have to go back and shift-tab ad nauseam. Is there a style field that I'm missing somewhere?


You can also look into scalari-form plugin. It gives you much more and IDE independent. You are particuliary interested in alignArguments=true and if I remember correctly defaults should make the indentation as you want.

*Note, that it formats code after some sbt task, for instance sbt test, not when you press Ctrl+Alt+L or similiar in IntelliJ