Search code examples
intellij-ideacode-formatting

Intellij - how to force split on operator rather than on max size


How to tell intellij to split lines like Eclipse does:

    private static final boolean VERY_VERBOSE = !(System.getProperty( "veryverbose" ) == null
            || System.getProperty( "veryverbose" ).equalsIgnoreCase( "false" ));

and not like this:

    private static final boolean VERY_VERBOSE = !(System.getProperty( "veryverbose" ) == null || System.getProperty(
            "veryverbose" ).equalsIgnoreCase( "false" ));

That translates to if there is an operator prefer to split on it rather than truncate the line at maximum size

Notes:
• I have hard-limit set to 120 (And I prefer to keep it like that)
• I imported the eclipse preferences to Intellij but IJ still misbehave

I Use intelliJ ultimate 2023.1.2


Solution

  • Try enabling the following options under Settings/Preferences (on macOS) | Editor | Code Style | Java | Wrapping and Braces:

    • Binary expressions => Wrap if long
    • Binary expressions | Operation sign on next line => Enable