How do I auto-indent Python code in Visual Studio Code? - visual-studio-code

I'm using Visual Studio Code (not Visual Studio) on Linux and I can't seem to find out how to turn on auto-indentation for Python. I've looked all over preferences, spent some time on Google, and can't find anything.
Does anyone know how to do this?

In VS Code you can set the indentation in several places :
General/Workspace settings (bottom bar),
User settings,
language formatter settings.
When using Python, no matter what settings you set, all of them are overridden by the autopep8Args value of the autopep8 language formatter setting, which has an indent size of 4.
By default, autopep8 is used as VS Code Python formatter, but there are others, like yapf.
To update the indent size of this formatter, search in your user settings the "python.formatting.autopep8Args" and set it to : ["--indent-size=2"],
"python.formatting.autopep8Args": ["--indent-size=2"],

Visual Studio Code doesn't have much support for Python (yet), aside from syntax-highlighting, and per-file intellisense (meaning it'll provide suggestions for symbols that have been found within the current file).
I'm willing to bet that the Visual Studio Code team will, eventually, increase their support for Python within Visual Studio Code, and with this, they'll likely add support for auto-indentation.
In the meantime, it might be worth trying this Visual Studio Code extension, which aims to add better support for Python, into Visual Studio Code.
The extension does add auto-indentation for Python, to Visual Studio Code, along with many other features.
Happy scripting!

I auto-format python with autopep8, vscode can use it. It can be easily configured for tab-size and other stuff creating the config file: $HOME/.config/pep8
Here an example of that file:
[pep8]
indent-size = 2
max-line-length = 100

Related

Is there any way to highlight a file in the Visual Studio Code explorer?

As a reminder, I would like to be able to highlight a file (in Explorer) that I have made important changes to. Highlighting it would make it easy to find again!
Visual Studio Code still doesn't provide such a feature. If you have source control, it will allow you to track modified files unless it is not available yet.

How do we change the formatter extension on Visual Studio Code if there are multiple ones?

Suppose we have a default code formatter on Visual Studio Code, and we install Prettier and a couple to formatter extensions to try out.
VSC would ask us which one we would like to use, but after that
how to we invoke a different one and
how do we change the default to a particular one?
As per VSCode official doc,
By default, the Extensions view will show the extensions you currently
have enabled...
You can switch to a different code formatter by disabling(using the small gear icon for that specific extension) and by enabling the one of your choice.

How to show line numbers of a python notebook in Visual Studio Code

I think it should be quite straightforward, however, I cannot seem to find this option in visual studio code.
Could you tell me if it is possible and how to enable line numbers in visual studio code when coding in a python notebook?
FYI: it is possible to use visual studio code with a python notebook (you can check more info here)
You have to press L after clicking on the left side of the code block.
as mention in the link provided you just need to press the L key
https://code.visualstudio.com/docs/python/jupyter-support#_enabledisable-line-numbers

How to change Intellisense priority in Visual Studio Code

How do I change the priority of the abbreviation recommendations inside Visual Studio Code? The file in question is a .scss file and I have tried with and without the Sass extension in Code installed. As far as I can tell currently it just lists them out in an alphabetical order. Is there any way to change this? I am genuinely surprised about how many people praise this editor when it has such huge flaws, that to my knowledge aren't solved yet.
https://github.com/Microsoft/vscode/issues/26127 says to "Disable the quick suggestions altogether" ?!
In VS Code 1.16 (the current insiders build) you can force emmet suggestions to the top by setting:
"editor.snippetSuggestions": "top",
"emmet.showSuggestionsAsSnippets": true

How to assimilate into visual studio code from visual studio ( the difference of hotkeys )?

I have been using VS for years. I'm trying to use vscode to develop frontend project.
This is my first time touching visual studio code. I feel the hotkeys are so different when compared with visual studio 2015. For example, format code in VS is ctrl+k+f and format code in visual studio 2015 is shift+alf+f. If I even want to perform a simple copy/paste folder operation I also cannot.
As I know, visual studio code supports customized hotkeys. So, I think that someone may have already config the hotkeys in a form like visual studio 2015.
However, I'm not sure this is even possible.
Please give me some suggestion or direction.
There are a few ways to solve this:
manually recreating all the keys you love from Visual Studio in your keybindings.json
Hoping somebody else has made one that you can copy and paste into your keybindings.json -- I can't find any
Find one in the marketplace. There are a few keybinding extensions, but I don't see any for Visual Studio, though there is a Resharper one if you're used to that.
If you do end up doing number 1, you could benefit the community by bundling it as an extension to share on the marketplace.
Edit: typo. exceptions -> extensions