348

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?

smac89
  • 39,374
  • 15
  • 132
  • 179
user3685412
  • 4,057
  • 3
  • 16
  • 16
  • possible duplicate of [Vertical column in Intellij Idea at arbitrary position](http://stackoverflow.com/questions/19206238/vertical-column-in-intellij-idea-at-arbitrary-position) – KeatsPeeks Jun 22 '14 at 21:39
  • 4
    See the linked question : Preferences -> CodeStyle -> General -> Right margin – KeatsPeeks Jun 22 '14 at 21:40
  • 2
    You should use that feature to improve the readability of your code. It's a good feature. I set mine to 80 characters. – Kevin Beal Jan 23 '18 at 22:12
  • Right, no need to worry about fellows with fHD who will possibly read your code in future – chill appreciator Jan 11 '22 at 08:24

7 Answers7

471

IntelliJ IDEA 2018

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

Code Style > Hard wrap at

IntelliJ IDEA 2016 & 2017

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

File > Settings

Editor > Code Style > Right margin

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • 50
    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 – Edu Castrillon Oct 15 '15 at 15:26
  • IntelliJ IDEA 2016.2.1 Ultimate on Windows is the same. – Vy Do Aug 25 '16 at 06:36
  • 1
    I also like the "Wrap on typing" option. It does all the alignment for me. – Zajo Jan 03 '18 at 15:35
  • 3
    It's now an option called "Hard wrap at" located in the same tab. – Kevin Beal Jan 23 '18 at 22:09
  • What about plebs that have smaller monitors(1080p, etc.) and possibly will look on your graceful long lines? Also what about Git conflicts when you need horizontal scroll in 3 windows in row? – chill appreciator Jun 15 '21 at 15:38
82

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

jcklie
  • 4,054
  • 3
  • 24
  • 42
40

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:

enter image description here

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

enter image description here

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

enter image description here

Andrzej Rehmann
  • 12,360
  • 7
  • 39
  • 38
18

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:

enter image description here

Marcin T.P. Łuczyński
  • 3,255
  • 1
  • 20
  • 15
17

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
cck
  • 502
  • 4
  • 17
7

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)'

Jelle den Burger
  • 1,428
  • 17
  • 31
5

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
ᴍᴇʜᴏᴠ
  • 4,804
  • 4
  • 44
  • 57