Ansuman Bebarta
Ansuman Bebarta

Reputation: 7246

How do I set the maximum line length in PyCharm?

I am using PyCharm on Windows and want to change the settings to limit the maximum line length to 79 characters, as opposed to the default limit of 120 characters.

Where can I change the maximum amount of characters per line in PyCharm?

Upvotes: 411

Views: 284974

Answers (9)

armanexplorer
armanexplorer

Reputation: 345

You can also make use of editorconfig and create the .editorconfig file in the root of the project with content like this:

# top-most EditorConfig file
root = true

[*.py]
max_line_length = 80

You can also replace [*.py] with [*] to apply this config to all files (not only to python files).

Note: This worked for me on PyCharm Professional 2024.1.1.

Upvotes: 0

HeyMan
HeyMan

Reputation: 1845

For PyCharm 2021.x this did the trick for python: enter image description here

Upvotes: 9

ZhefengJin
ZhefengJin

Reputation: 1092

For PyCharm 2019.3.1, I see this.

enter image description here

Upvotes: 4

lmiguelvargasf
lmiguelvargasf

Reputation: 69695

For PyCharm 2018.1 on Mac:

Preferences (+,), then Editor -> Code Style:

enter image description here

For PyCharm 2018.3 on Windows:

File -> Settings (Ctrl+Alt+S), then Editor -> Code Style:

To follow PEP-8 set Hard wrap at to 80.

Upvotes: 84

Steve Stacha
Steve Stacha

Reputation: 198

For anyone, or myself if I reload my machine, who this is not working for when you do a code reformat there is an additional option to check under editor->code style->python : ensure right margin is not exceeded. Once this was selected the reformat would work.

preference_highlighted

Upvotes: 10

Abhishake Gupta
Abhishake Gupta

Reputation: 3170

For PyCharm 2017

We can follow below: File >> Settings >> Editor >> Code Style.

Then provide values for Hard Wrap & Visual Guides for wrapping while typing, tick the checkbox.

NB: look at other tabs as well, viz. Python, HTML, JSON etc.

Upvotes: 1

andy
andy

Reputation: 4281

You can even set a separate right margin for HTML. Under the specified path:

File >> Settings >> Editor >> Code Style >> HTML >> Other Tab >> Right margin (columns)

This is very useful because generally HTML and JS may be usually long in one line than Python. :)

Upvotes: 7

Alex G.P.
Alex G.P.

Reputation: 10011

Here is screenshot of my Pycharm. Required settings is in following path: File -> Settings -> Editor -> Code Style -> General: Right margin (columns)

Pycharm 4 Settings Screenshot

Upvotes: 611

Marco Sanchez
Marco Sanchez

Reputation: 788

For PyCharm 4

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

suggestion: Take a look at other options in that tab, they're very helpful

Upvotes: 25

Related Questions