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?
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.
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.
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 ).
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.
Disable the following code style option - Project Settings - Code Style - Wrapping and Braces - Keep when reformatting - Line breaks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With