ChatGPT解决这个技术问题 Extra ChatGPT

How to change line width in IntelliJ (from 120 character)

I was wondering how I can change the line length in IntelliJ.

Since I use a pretty high resolution, I get that line that shows 120 characters straight through the middle of the screen. Can I change it from 120 to, say, 250?

See the linked question : Preferences -> CodeStyle -> General -> Right margin
You should use that feature to improve the readability of your code. It's a good feature. I set mine to 80 characters.
Right, no need to worry about fellows with fHD who will possibly read your code in future

R
ROMANIA_engineer

IntelliJ IDEA 2018

File > Settings... > Editor > Code Style > Hard wrap at

https://i.stack.imgur.com/jMY9v.png

IntelliJ IDEA 2016 & 2017

File > Settings... > Editor > Code Style > Right margin (columns):

https://i.stack.imgur.com/1hw1e.png

https://i.stack.imgur.com/2zO2o.png


I would also add that, to enforce this value when formatting, you should activate Settings -> Editor -> Java/Groovy/JSON -> Wrapping and Braces -> Ensure right margin is not exceeded
IntelliJ IDEA 2016.2.1 Ultimate on Windows is the same.
I also like the "Wrap on typing" option. It does all the alignment for me.
It's now an option called "Hard wrap at" located in the same tab.
@EduCastrillon Too bad not all of the available languages support this feature. For example, SQL dialects seems to be missing it.
j
jcklie

You can alter the "Right margin" attribute in the preferences, which can be found via

File | Settings | Project Settings | Code Style - General

Right Margin (columns) In this text box, specify the number of columns to be used to display pages in the editor.

Source: Jetbrains


A
Andrzej Rehmann

It seems like Jetbrains made some renaming and moved settings around so the accepted answer is no longer 100% valid anymore.

Intellij 2018.3:

hard wrap - idea will automatically wrap the line as you type, this is not what the OP was asking for

visual guide - just a vertical line indicating a characters limit, default is 120

If you just want to change the visual guide from the default 120 to lets say 80 in my example:

https://i.stack.imgur.com/LODn6.png

Also you can change the color or the visual guide by clicking on the Foreground:

https://i.stack.imgur.com/FUmPU.png

Lastly, you can also set the visual guide for all file types (unless specified) here:

https://i.stack.imgur.com/45hqD.png


c
cck

Be aware that need to change both location:

File > Settings... > Editor > Code Style > "Hard Wrap at"

and

File > Settings... > Editor > Code Style > (your language) > Wrapping and Braces > Hard wrap at

M
Marcin T.P. Łuczyński

It may be useful to notice that very good answers given above may not be enough. It is because of one more tick is required here:

https://i.stack.imgur.com/h2thW.png


Thats what I was looking for, Did not understand whats Hard Wrap there then. Just say page size
Doesn't seem to be there anymore in 2019.
J
Jelle den Burger

I didn't understand why my this didn't work but I found out that this setting is now also under the programming language itself at:

'Editor' | 'Code Style' | < your language > | 'Wrapping and Braces' | 'Right margin (columns)'


m
mehov

Open .editorconfig in the root of your project (or create one if you don't have any) and add:

max_line_length = 80

The IDE should pick it up immediately (works in phpStorm, developed by the same company). As a bonus, it can be committed to GIT and will stay consistent across different editors you may be using in the future. More info on .editorconfig.