Disable auto wrap long line in Visual Studio Code

PythonVisual Studio-CodePylint

Python Problem Overview


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.

Python Solutions


Solution 1 - Python

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"
]

Solution 2 - Python

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:

https://stackoverflow.com/questions/54030320/vscode-autopep8-allow-statements-before-imports/54031007#54031007

Solution 3 - Python

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}"
],

Solution 4 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKymo WangView Question on Stackoverflow
Solution 1 - PythonChayapolView Answer on Stackoverflow
Solution 2 - PythonMeetai.comView Answer on Stackoverflow
Solution 3 - PythonAndy BrownView Answer on Stackoverflow
Solution 4 - PythonRob HaswellView Answer on Stackoverflow