How do I enable indentation in VS Code?
I'm trying to learn Python (newbie in programming) and need auto-indentation. It worked with the first version I tried, but it doesn't indent after a colon (:
) anymore. How can I configure it to automatically indent?
As said there is the python extension which now do it out of the box, but still don't do a great job, and example is when you copy and past a whole block into a function or so, it just indent the first line, that's not a good behavior. here are two good helpful solutions:
python auto indent extension (https://marketplace.visualstudio.com/items?itemName=hyesun.py-paste-indent), it solve the problem when pasting. just see how it work in the link. Now about setting it up, you need to set just one keybinding. for the command "pyPasteIndent.pasteAndIndent" provided by the extension. Once done you will have your own shortcut to past and indent automatically (i have set it to ALT+P)
Here HOW: - CTRL+SHIFT+P to open command pallet, then write "key"*, choose *"open keyboard shortcut", then the keybinding page open, which it's the nice interface for the **keybindings.json. You can open keybindings.json the same way and by choosing "open keyboard shortcut file" (in place of just "open keyboard shortcut"). Give it a look if never have. But here i will go with the nice Interface, know also that you can open that Going File>Preference>Keyboard Shortcut.
In the keybinding window, in the search bar, past pyPasteIndent.pasteAndIndent, then click + button to add the shortcut and create the keybinding.
The image bellow show well how it's done:
You can install VSCode python extension which will provide intellisense, auto-completion, code formatting, and debugging. Here is more information on the python extension, here