Reputation: 1513
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.
Upvotes: 141
Views: 94016
Reputation: 123
You can use BlackFormatter
as your default formatter, than you put this line in your settings.json
:
"black-formatter.args": ["--line-length","120"]
Upvotes: 0
Reputation: 528
What worked for me to set the desired line length with
VSCode v1.90.2 (July 2024) and autopep8 v2024.0.0
in VSCode settings, Extensions.autopep8.Args add 2 items
--max-line-length=120
and --experimental
(without any quotes, if doesn't work check the autopep8 output).
Upvotes: 0
Reputation: 2865
In VS Code version 1.82.2 (2023), the location for parsing autopep8's arguments has changed.
Now you should add the following to the top level of the settings.json
file:
"autopep8.args": ["--max-line-length=120"]
or remove the lenght limit completely:
"autopep8.args": ["--ignore=E501"]
Upvotes: 21
Reputation: 11
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.
Upvotes: 1
Reputation: 6928
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
Upvotes: 14
Reputation: 12999
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}"
],
Upvotes: 1
Reputation: 3934
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"
]
Upvotes: 282
Reputation: 97
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.
Upvotes: -1