Skip to content

Instantly share code, notes, and snippets.

@atulkumar2
Created April 27, 2022 06:15
Show Gist options
  • Save atulkumar2/aaa0beeaf2df06b30578bfe36b5dc8cd to your computer and use it in GitHub Desktop.
Save atulkumar2/aaa0beeaf2df06b30578bfe36b5dc8cd to your computer and use it in GitHub Desktop.
Format Python files using 2 spaces in VSCode

This is to allow format document feature in VSCode to format the file using 2 spaces instead of 4.

https://stackoverflow.com/questions/54430470/vs-code-python-autopep8-does-not-honor-2-spaces-hanging-indentation https://stackoverflow.com/a/70932095

  • Navigate to library directory of your environment
  • Open autopep8.py
  • Search for "DEFAULT_INDENT_SIZE" and change it to 2

If using minioconda, autopep8.py file can be found in the location as below

  • miniconda3/envs/ENVNAME/lib/python3.10/site-packages/autopep8.py

In case of anaconda, this will probably be

  • anaconda3/envs/ENVNAME/lib/python3.10/site-packages/autopep8.py

Additionally, E121 can be added in the ignore list in the autopep8.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment