How to make Python code automatically indented in Visual Studio Code?

I am using Visual Studio Code (not Visual Studio) on Linux, and I cannot figure out how to enable auto-skipping for Python. I looked through all the preferences, spent some time on Google and found nothing.

Does anyone know how to do this?

+6
source share
2 answers

In VS Code, you can indent in several places:

  • General / Workspace options (bottom line),
  • User settings
  • Language formatting settings.

When using Python, no matter what settings you set, they are all overridden by the autopep8Args value of the autopep8Args parameter to format a language whose size is not 4.

By default, autopep8 used as the VS Code Python code formatter, but there are others like yapf .

To update the indent size of this formatting, search your user settings for "python.formatting.autopep8Args" and set it: ["--indent-size = 2"],

 "python.formatting.autopep8Args": ["--indent-size=2"], 
+1
source

Visual Studio code does not have much support for Python (yet), other than syntax highlighting and per-file intellisense (which means that it will provide suggestions for characters found in the current file).

I bet that the Visual Studio Code team will eventually increase Python support in Visual Studio Code, and with that they are likely to add support for automatic indentation.

At the same time, it might be worth trying this Visual Studio Code Extension , whose goal is to improve Python support in Visual Studio Code.

The extension adds auto-indexing for Python to Visual Studio Code, as well as many other features.

Happy scripts!

0
source

All Articles