Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ force code formatter to join lines based on wrap settings

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?

like image 472
Jesper Rønn-Jensen Avatar asked Aug 19 '11 09:08

Jesper Rønn-Jensen


People also ask

How do I join lines in IntelliJ?

Place the caret on the line that you want to join with a lower line and press ⌃⇧J (macOS), or Ctrl+Shift+J (Windows/Linux), to join lines of code.

How do I fix code format in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.

How do I format multiple lines in IntelliJ?

Go to Settings/Preferences | Editor | Code Style, select your programming language, and open the Wrapping and Braces tab. In the Keep when reformatting section, select the formatting rules which you want to ignore and deselect those which should be applied. Reformat your code ( Ctrl+Alt+L ).

How do I enable line wrap in IntelliJ?

You can enable soft wrap for the editor with ⇧⇧ (macOS), or *Shift+Shift (Windows/Linux), for the Search Everywhere dialogue, and then typing in soft wrap. You can also go to Preferences/Settings > Editor > General to enable Soft Wraps for more file types by default.


1 Answers

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

like image 66
denis.zhdanov Avatar answered Sep 22 '22 15:09

denis.zhdanov