IntelliJ force code formatter to join lines based on wrap settings
Asked Answered
D

2

9

How can i reformat file(s) in IntelliJ and join all lines that are split.

I know that I can do that individually by selecting lines and "join lines" with CTRL + SHIFT + J

Since we changed our code formatting wrap policy recently I want to be able to join lines in all files based on the updated wrap setting. (Settings > Code Style > General > Right margin)

The only thing is that IntelliJ seems happy to split lines based on wrap setting, but will silently deny to join lines based on that setting.

Unlike the question Force code formatter in IntelliJ to join lines, I am not satisfied by splitting lines or joining manually (as the accepted answer suggests). I want IntelliJ to join lines automatically.

Bonus question: Which other editors can do this?

Domitiladomonic answered 19/8, 2011 at 9:23 Comment(0)
F
16

Disable the following code style option - Project Settings - Code Style - Wrapping and Braces - Keep when reformatting - Line breaks

Fallal answered 23/8, 2011 at 14:22 Comment(1)
Thanks! Note to self: The setting has to be UNCHECKED (bad wording in interface, since it is confusing that you uncheck in order for the editor to take action)Remote
L
2

IntelliJ IDEA 15

  • File > Settings... > Editor > Code Style > Java > Wrapping and Braces > Keep when reformatting > uncheck Line breaks

    uncheck Line breaks

    (if you want to have the same setting for another type of file, choose it from Code Style)

  • Go to Code > Reformat Code (Ctrl + Alt + L).

Leah answered 1/1, 2016 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.