Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable auto wrap long line in Visual Studio Code

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.

like image 965
Kymo Wang Avatar asked Nov 21 '17 06:11

Kymo Wang


People also ask

How do I turn off word wrap in VS Code?

Basic Editing in Visual Studio Code By default, editor. wordWrap is off but if you set to it to on, text will wrap on the editor's viewport width. "editor. wordWrap": "on" You can toggle word wrap for the VS Code session with ⌥Z (Windows, Linux Alt+Z).

How do you break a long code line in Visual Studio?

Use the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break. The underscore must be immediately preceded by a space and immediately followed by a line terminator (carriage return) or (starting with version 16.0) a comment followed by a carriage return.


3 Answers

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"
]
like image 89
Chayapol Avatar answered Oct 16 '22 09:10

Chayapol


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

like image 7
Meetai.com Avatar answered Oct 16 '22 10:10

Meetai.com


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}"
],
like image 1
Andy Brown Avatar answered Oct 16 '22 09:10

Andy Brown