Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Python language specific tab spacing in Visual Studio Code?

Using VSCode 1.9.0 with the (donjayamanne) Python 0.5.8 extension, is it possible to provide Python specific editor options?

Or more generally speaking, is it possible to provide language specific tab spacing and replacement rules? For example, Python should be tab=4 spaces (replaced as spaces), and Ruby should be tab=2 spaces (replaced). Other languages tend to have their own opinions. However, I only see the general

"editor.tabSize": 4, "editor.insertSpaces": true, 

options.

I thought perhaps there was a "python.editor": { } block or perhaps a "python.editor.tabSize" option, but I can't find reference to such, nor have I successfully guessed a working name.

like image 398
michael_teter Avatar asked Feb 08 '17 16:02

michael_teter


People also ask

How do I change the tab spacing in VS code?

Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately. If this doesn't happen (it's a little lag sometimes), just reload or restart your VS Code.

How do I change the default space in VSCode?

You can click on the Status Bar indentation display to bring up a dropdown with indentation commands allowing you to change the default settings for the open file or convert between tab stops and spaces.


1 Answers

I had the same problem today.
This is how I fixed it. Add this lines in setting.json in VSCode:

"[python]": {   "editor.insertSpaces": true,   "editor.tabSize": 4   } 

It works like a charm.

like image 156
zeljko_a Avatar answered Sep 21 '22 09:09

zeljko_a