问题:如何在PyCharm中设置最大行长?

我在Windows上使用PyCharm,并且想要更改设置以将最大行长限制为79字符,而不是默认的120字符限制。

我在哪里可以更改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?


回答 0

这是我的Pycharm的屏幕截图。所需设置在以下路径中:File -> Settings -> Editor -> Code Style -> General: Right margin (columns)

Pycharm 4设置截图

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


回答 1

对于Mac上的PyCharm 2018.1:

首选项(+ ,),然后Editor -> Code Style

在此处输入图片说明

对于Windows上的PyCharm 2018.3:

文件->设置(Ctrl+ Alt+ S),然后Editor -> Code Style

要遵循PEP-8,请将其设置Hard wrap at为80。

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.


回答 2

对于PyCharm 4

文件>>设置>>编辑器>>代码样式:右边距(列)

建议:查看该标签中的其他选项,它们非常有帮助

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


回答 3

您甚至可以为HTML 设置单独的右边距。在指定路径下:

文件>>设置>>编辑器>>代码样式>> HTML >>其他选项卡>>右页边距(列)

这非常有用,因为通常HTML和JS的一行通常比Python长。:)

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. :)


回答 4

对于任何人,或者对于我自己,如果我重新加载计算机,在进行代码重新格式化时这对谁都不起作用,那么还有一个附加选项可在editor-> code style-> python下检查:确保未超出正确的边距。选择此选项后,格式将生效。

preference_highlighted

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


回答 5

对于PyCharm 2017

我们可以按照以下步骤进行操作:文件>>设置>>编辑器>>代码样式。

然后在键入时为Hard Wrap&提供值Visual Guides for wrapping,勾选复选框。

注意:也请查看其他标签。Python,HTML,JSON等

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.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。