Prevent intellij from formatting strings

Answered

Hi!

I have this java code.


      String str = "a"
       + "b"
       + "c";

When I format code with Ctrl + Alt + L

It becomes just 

String str = "a" + "b" + "c";

How can I prevent this?

 

I want to have pretty printed json in string and that is why I don't want intellij to mess it up.

0
3 comments

See if it helps to enable the option to preserve existing line breaks in the settings:

0

Thanks it helped.

 

I read this yesterday https://www.jetbrains.com/help/idea/reformat-and-rearrange-code.html#reformat_module_directory but couldn't figure out why Do not keep line breaks wasn't showing for me. After enabling what you suggested I started to see  Do not keep line breaks.  Now I see it says “This option overrides the Keep when reformatting | Line breaks setting.” but I think this hint is kinda too cryptic.  Would be  good if your screenshot could be added there somehow.

0
Thanks for the suggestion, I asked our tech writers to update the documentation page accordingly.
0

Please sign in to leave a comment.