125

I use Visual Studio Code to write Python code with Pylint.

When I press Ctrl + S (save), the editor wraps a long line into multiple short lines. How do I disable the action or configure wrap column count to 120 (default is 80)?

I have tried "python.linting.pylintArgs": ["--max-line-length=120"] and "editor.wordWrapColumn": 120, but it didn't work.

2
  • 2
    Do you have automatic formatting turned on? VS Code itself won't reformat anything, so editor.wordWrapColumn won't affect that as that -- along with editor.wordWrap -- only affect how to display long lines, not rewrite them. Nov 27, 2017 at 22:00
  • 3
    If you use autopep8, do the following: open "Settings"-> search "python formatting autopep8 args" -> click "Add Item" -> type --max-line-length=120 (change 120 to you preferred length).
    – Divelix
    Sep 29, 2021 at 9:17

5 Answers 5

270

Check your Python formatting provider.

"python.formatting.provider": "autopep8"

I guess in your case it is not Pylint which keeps wrapping the long lines, but autopep8. Try setting --max-line-length for autopep8 instead.

"python.formatting.autopep8Args": [
    "--max-line-length=200"
]
7
  • 12
    It also helps if the linter behaves similarly to the formatter: "python.linting.pep8Args": ["--max-line-length=120"]
    – Lian
    Apr 5, 2018 at 15:15
  • 3
    For information about other available arguments, see pypi.org/project/autopep8 Feb 4, 2019 at 15:51
  • 1
    TLDR: PEP8 indicates that the ideal line wrapping limit for Python is 80, so this is the default for the autopep8. Oct 28, 2019 at 6:52
  • 33
    with pure point & click achieve this with: "Code -> Preferences -> Settings". Then select "Extensions -> Python". Browse through to "Formatting: Autopep8 Args" and its "Add item", in the proposed box, add "--max-line-length=200" Apr 23, 2020 at 6:23
  • 15
    "--ignore=E501" to completely ignore max-line-length.
    – Jeppe
    Jun 23, 2020 at 7:07
13

When using custom arguments, each top-level element of an argument string that's separated by space on the command line must be a separate item in the arguments list. For example:

"python.formatting.autopep8Args": [ 
  "--max-line-length", "120", "--experimental" 
],
"python.formatting.yapfArgs": [
  "--style", "{based_on_style: chromium, indent_width: 20}"
],
"python.formatting.blackArgs": [
  "--line-length", "100"
]

For proper formatting of these Python settings you can check Formatter-specific settings:

Also check the answers here:

Allow statements before imports with Visual Studio Code and autopep8

1

If you're using yapf as your formatter then the option is column_limit. For example, from settings.json:

"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": [
    "--style={based_on_style: google, indent_width: 4, column_limit: 150}"
],
0

I tried the solution with different way. Search in VSC settings for "Autopep8". And as you can see there is an "Add Item" button in here. You can simply click it and paste the code there. The code will add in your "settings.json" file.

screenshot

-2

Autopep8 requires --aggressive in order to recommend non-whitespace changes:

"python.linting.pylintArgs": ["--max-line-length", "120", "--aggressive"]

This will wrap the long lines for you.

1
  • 1
    I believe OP is asking how to disable wrapping, not how to enable it Jun 30, 2022 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.