Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio, Python not auto-indenting

This is probably a simple issue but something is wrong with my Python tools for visual studio. When I first started using VS2015 for Python it would auto-indent whenever I used a colon. Now VS2015 is just acting like a text editor with syntax highlighting. I tried uninstalling and reinstalling the Python tools but that did not work. How do I fix Visual Studio to auto-style as I write Python again?

like image 601
Nick Gilbert Avatar asked Mar 02 '16 18:03

Nick Gilbert


People also ask

How do I fix indentation in Visual Studio Python?

Go to "Command Palette" Ctrl + Shift + P (View>Command Palette) Type in & select "Convert Indentation to Tabs" and press Enter.

How do I turn on auto indent in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

How do I indent a Python code automatically?

Use the reindent.py script that you find in the Tools/scripts/ directory of your Python installation: Change Python (. py) files to use 4-space indents and no hard tab characters. Also trim excess spaces and tabs from ends of lines, and remove empty lines at the end of files.

How do I automatically fix indentation in Visual Studio code?

Press Ctrl+Shift+P to open Command Palette. Type in settings and select Open User Settings. In Search settings box, input indent to search for settings related to indentation. Select full in Editor: Auto Indent section.


2 Answers

Tools -> Options -> Text editor -> Python -> Tabs and set it to Smart

like image 151
Cosmin Avatar answered Sep 19 '22 15:09

Cosmin


http://stevedower.id.au/blog/smart-indentation-for-python/

However, the most common (and default) mode is “Smart.” Unlike the other two modes, which are built into the editor, smart indentation is provided by a language service (which are also responsible for providing syntax highlighting and completions). Because they are targeted to a specific language, they can help the programmer by automatically adding and removing extra indentation in ways that make sense.

like image 25
Kozubi Avatar answered Sep 20 '22 15:09

Kozubi