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.
All you need is to export settings from Eclipse (go to Eclipse's Preferences → Java → Code Style → Formatter and export the settings to an XML file via the Export All button.), and then open IntelliJ IDEA Settings → Code Style → Java, click Manage, and import that XML file by simply clicking Import.
Ensure right margin is not exceeded
File > Settings > Editor > Code Style > Java > Wrapping and Braces > Ensure right margin is not exceeded
Reformat code
Code > Reformat code...
or press Ctrl + Alt + L
If you have something like this:
thisLineIsVeryLongAndWillBeChanged(); // comment
it will be converted to
thisLineIsVeryLongAndWillBeChanged();
// comment
instead of
// comment
thisLineIsVeryLongAndWillBeChanged();
This is why I select pieces of code before reformatting if the code looks like in the previous example.
IntelliJ IDEA 14: File > Settings > Editor > Code Style > Wrap when typing reaches right margin
IntelliJ IDEA 15, 2016 & 2017: File > Settings > Editor > Code Style > Wrap on typing
Do you mean that the formatter does not break long lines? Then please check:
Settings / Project Settings / Code Style / Wrapping
Update: In later versions of IntelliJ, the option can be found under:
Settings / Editor / Code Style
There select Wrap when typing reaches right margin
.
Enabling "Ensure right margin is not exceeded" doesn't work for me in Intellij IDEA 2018.2. I have found the workaround, we need to change every elements below from "Do not wrap" to "Wrap if long".
After that, we can preview what kind of wrap type will be changed by looking into right panel. If we are satisfied, Click "OK" or "Apply" to apply the changes. Finally we need a mannual format by using CTRL+ ALT+ L in Windows and Command+ Shift+ L in MacOS.
Or you can use the shortcut:
Ctrl + Alt + L
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