How do I make my source code of python to forced using 2 spaces indentation when clicking save file. ChatGPT code generated always produce 4 spaces that's why I asked this. I don't feel comfortable for 4 spaces indentation in python. I tried autopep8 formatter extension but it didn't help me.
Here is my current .vscode/settings.json
{
"editor.tabSize": 2,
"editor.defaultFormatter": "ms-python.autopep8",
"editor.autoIndent": "brackets",
"editor.indentSize": "tabSize",
"editor.detectIndentation": true,
"editor.insertSpaces": true,
"autopep8.args": [
"--indent-size=2"
]
}
I expect from here:
if __name__ == '__main__':
asyncio.run(main())
To the here after save the file:
if __name__ == '__main__':
asyncio.run(main())
Replying @Tim240 answer:
Here are I attached the screenshots, it seems same:



Using
editor.formatOnSave: trueand thenCtrl+Shift+PtypeFormat Documentand then selectautopep8, it worked!Here is my current
settings.json: