9

I'm looking to enable automatic indentation of Python function arguments, as shown in the example below generated with use of . I had a look at a similar discussion but the discussed solutions do not appear to solve this problem.

Desired Behaviour

PyCharm

VS Code

VS Code indentation


  • VS Code version: 1.27.2
  • Python extension: 2018.8.0 (04 September 2018)

Update

  • Current autoIndent setting enter image description here
Konrad
  • 17,740
  • 16
  • 106
  • 167

2 Answers2

7

This is a known issue for the Python VSCode extension and it can currently not be fixed because of limitations in the extension API. More specifically the line in the editor cannot know the content of other lines. I am not aware of any fix for this issue, but I agree that it decreases the experience of working with VSCode by far.

See this issue for further information: https://github.com/Microsoft/vscode-python/issues/701

larsl
  • 338
  • 1
  • 10
  • Thanks very much for your answer. I’ll accept as I reckon that there is no scope for a better solution until the issue you mentioned is resolved. – Konrad Sep 28 '18 at 13:15
  • @Konrad try using a formatter for VSCode and enable it on save, e.g. yapf https://code.visualstudio.com/docs/python/editing#_formatting – larsl Nov 12 '18 at 16:18
7

Like @larsl already wrote, this is currently a limitation of the basic Microsoft python extension. However, fellow VS Code user Kevin Rose was so kind to write an extension that does exactly what we were looking for:

https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent

As far as my early experience with it goes, it works like a charm!

Jannik Buhr
  • 1,788
  • 2
  • 11
  • 11