Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 285
antikantian Avatar asked Oct 10 '16 18:10

antikantian


People also ask

How do I change indentations in IntelliJ?

If you need to adjust indentation settings, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. On the appropriate language page, on the Tabs and Indents tab, specify the appropriate indents options and click OK.

How do I indent left in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. Select the Detect and use existing file indents for editing checkbox.

What are smart tabs IntelliJ?

IDEA has a “smart tabs” option that you can turn on: If this check box is selected, IntelliJ IDEA inserts tabs for indentation and reformatting, but fine alignment to a necessary column is done only via spaces. This is done in order to preserve visual representation of the source code, when the Tab Size is changed.


1 Answers

There's an Intellij only solution:

Under Wrapping and Braces, disable Method declaration parameters > Use normal indent for parameters.

Then, under Other, enable Alternate indentation for constructor args and parameter declarations and set to the number of spaces you want to indent from the declaration level (in your case 4).

like image 165
tswei Avatar answered Oct 29 '22 03:10

tswei