字符串换行时的 Intellij IDEA 加号

我正在使用 Intellij IDEA 10.5社区。 如果我有一个很长的字符串并且想要分割成多行,我在字符串的中间按 ENTER 键,得到如下结果:

String str = "ONE LONG" +
"STRING";

有没有可能把 + 号放在行首,像这样:

String str = "ONE LONG"
+ "STRING";
22797 次浏览

Settings (Preferences on macOS) | Editor | Code Style | Java | Wrapping and Braces | Binary expressions | Operation sign on next line:

Operation sign on next line

In IntelliJ 15 this setting is in the preferences under

Editor > Code Style > Java > Wrapping and Braces (tab) > Binary Expressions (group) > Operation sign on next line (check box)

In case someone is using Android Studio:

Android Studio > Settings > Editor > Code Style > Java

Click on tab "Wrapping and Braces" and then find the "Binary expressions" group. There you have the checkbox "Operation sign on next line"

In 2016.3 only this helped me:

while in editor, click on menu : code->generate->tostring->settings->template tab-> copy "String concat (+)", this would allow you to edit a new template.

then in template paste this:

public java.lang.String toString() {
#if ( $members.size() > 0 )
#set ( $i = 0 )
return "$classname{"
#foreach( $member in $members )
#if ( $i == 0 )
+ " ##
#else
+ ", ##
#end
#if ( $member.objectArray )
#if ($java_version < 5)
$member.name=" + ($member.accessor == null ? null : java.util.Arrays.asList($member.accessor)) +
#else
$member.name=" + java.util.Arrays.toString($member.accessor)
#end
#elseif ( $member.primitiveArray && $java_version >= 5)
$member.name=" + java.util.Arrays.toString($member.accessor)
#elseif ( $member.string )
$member.name='" + $member.accessor + '\''
#else
$member.name=" + $member.accessor
#end
#set ( $i = $i + 1 )
#end
+ '}';
#else
return "$classname{}";
#end
}