How to prevent IntelliJ from changing file formatting if lines meet hard wrap constraints?

Answered

Essentially, IntelliJ formats my code such that, even if it conforms to the 150 hard wrap limit, it will try to fit as much possible on each line.

 

If this limit has not been exceeded, how can I tell IntelliJ to leave my code alone?

1
8 comments

Tick "Wrap on typing" checkbox under Preferences | Editor | Code Style. And make sure to set Hard wrap at to preferred value, then change Do not wrap to Wrap if long (or Chop down if long) for all items in the Wrapping and Braces tab of code style setting for the language you are writing in. 

Also, check the similar threads

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004172899-Wrap-line-if-length-exceeds-

https://stackoverflow.com/questions/3837959/how-to-have-the-formatter-wrap-code-with-intellij/29922077

 

0

The issue still occurs despite changing the settings as can be seen here: https://i.imgur.com/Qi5wXdB.mp4

0

Check that "Wrap if long" is chosen for Binary operations, assignment statement, Chained Method calls, Method calls arguments

If that dow not help, please provide more details: 

- How wrapping and spaces tab is looking under code style for the language you are using (Am I right that it is Java?)
  https://i.imgur.com/g8QosP1.png

- Show the settings under Preferences | Editor | Code Style
    
https://i.imgur.com/z4Xu0rm.png

- Show what "Quick documentation" action does for the file you are working with 
    https://i.imgur.com/ByowdCg.png

 

0

Modifying my settings as requested, the issue still seems to persist.

1) You are correct in assuming that the language being used is Java. Here are all of the screenshots indicating all of my settings under that tab:

https://imgur.com/a/VH1KLZZ

2) Here are the settings under Preferences | Editor | Code Style:

https://imgur.com/a/wrsc8Uw

3) Here is what "Quick documentation" shows:

https://imgur.com/a/nh36aSl

0

Do you have .editorconfig file in the folder with the .java file? 

Can you check if other wrapping settings are working within this file (Forr example "Operation sign on the next line" for Binary operations)? 

Does the issue reproduce within the one project, or it could be reproduced with a plain "Hello world" project? Share the sample if you could create one.

You can use JetBrains FTP share:
https://intellij-support.jetbrains.com/hc/en-us/articles/206869619-Uploading-Large-Files-for-JetBrains-Support-Team

0

I do not seem to have an .editorconfig file in the folder with the .java file.

The wrapping settings do seem to work as intended otherwise.

I uploaded Hello World.zip via https://uploads.services.jetbrains.com/

The file is changed when reformatting is applied, which may be separate from the hard wrap issue now that I think about it.

0

> I uploaded Hello World.zip via https://uploads.services.jetbrains.com/

I do not see the file. Could you please upload it again? 

0

Please sign in to leave a comment.