Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When formatting multiline statements in IntelliJ IDEA, can I align operators?

I'm looking at the options in IntelliJ IDEA 12 and I can't let this go. So please help me stop wasting time on it.

This is some code from my Build.scala:

val logging =
  Seq(
    "ch.qos.logback" % "logback-classic" % "1.0.13",
    "org.slf4j" % "slf4j-api" % "1.7.5",
    "com.weiglewilczek.slf4s" % "slf4s_2.9.1" % "1.0.7"
  )

I'd like it to look like this:

val logging =
  Seq(
    "ch.qos.logback"          % "logback-classic" % "1.0.13",
    "org.slf4j"               % "slf4j-api"       % "1.7.5",
    "com.weiglewilczek.slf4s" % "slf4s_2.9.1"     % "1.0.7"
  )

And I prefer create that automatically with the code formatter. In my (unreliable) memory I had this working in IntelliJ IDEA before, but I can't find which options to turn on.

Do you know where this option is hiding?

like image 541
iwein Avatar asked Jun 04 '13 08:06

iwein


People also ask

How do I format multiple lines in IntelliJ?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. Switch to the Formatter tab and in the Do not format field, enter the files and directories that you want to exclude using a glob pattern. , the field will expand, and each pattern will be shown on a separate line.

How do I align lines in IntelliJ?

Open indentation settings in code style scheme Click the widget and select Configure Indents for 'Language'. In the dialog that opens, you can change settings for tabs and indents and also configure other code style settings. Click OK. Reformat the necessary part of your project to apply new indentation settings.

How can I beautify code in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings. You can also display the Reformat File dialog with ⌥⇧⌘L (macOS), or Ctrl+Alt+Shift+L (Windows/Linux).


1 Answers

There are many Align multiline options in IDEA, but none has an effect on this syntax.

This feature is not in IDEA 12. The only option that I could think of was to manually format the code that way. You should vote for this alignment feature request and anxiously await IDEA 13.

like image 85
iwein Avatar answered Nov 15 '22 04:11

iwein