Groovy enter-in-string literal

I am a fan of the feature in IDEA that changes:

System.out.println( "Hello, World!" );


System.out.println( "Hello, " +
                    "World!" );

when you type enter in a middle of a string literal. I use this all the time when I have strings to output that are too long for the editor. However, in Groovy, IDEA changes
println "Hello, World!"


println """Hello,

This introduces a newline into a string, plus makes horrible indenting. I find that I prefer the "Java-like" form much more often than the Groovy multi-line string format. Is there a way to configure IDEA to do this?

Comment actions Permalink

Currently this seems to be only possible manually. Enter behavior could be changed to be like in Java, but the current functionality is also quite useful, and it's not clear to me how to preserve it as well without making it undiscoverable.

Comment actions Permalink

I haven't done a huge amount of Groovy yet, but I am thinking 99% of the time when I want to type enter in the middle of a "string" that I'm wanting to wrap the line and not insert an actual newline character. I'm not quite sure why the situation is different for Groovy as for Java, is this a much more common pattern in Groovy to use triple quote instead of \n? IDEA could use an X+Enter key combo, but from what I can see, every combination of ctrl/alt/shift + enter already has a meaning, so that leaves two options for compromise:

  • Use Java-style string wrapping when in "string" but insert actual newline character into source code when in """string""" (applies to both single and double quote forms)
  • The above, but with editor option to set enter behavior inside "strings" and """strings""" (you could leave both settings to default how they work today, for consistency with old versions).

If configurable, the first option would be how I would configure it. This is because if I am making a string I know want to be a true multi-line string, I'm going to know before I start if I want a multi-line so I will open the string with triple quotes. In this case it should be apparent that I prefer newlines in source rather than \n.

Comment actions Permalink

Sounds reasonable.
I've filed a ticket for that:
Please vote/watch it.

Comment actions Permalink

Awesome, I have voted/star'd it.


Please sign in to leave a comment.