As already mentioned, there is a Python extension that now does this out of the box, but still does not do much work, and an example is when you copy and paste an entire block into a function or so, it just indentes the first line, this not good behavior. Here are two useful helpful solutions:
- Indent the whole block manually : select the entire block, then press TAB , if you want to indent back , do this with SHIFT + TAB . What is it, I think, that can be useful in several places.
The python auto-indent extension ( https://marketplace.visualstudio.com/items?itemName=hyesun.py-paste-indent ), it solves the insertion problem. just see how it works by reference. Now about the setup, you only need to set one key binding . for the pyPasteIndent.pasteAndIndent command provided by the extension. When you are done, you will have your own shortcut for the past and indentation automatically (I set ALT + P)
Here, HOW: - CTRL + SHIFT + P to open the command pallet, then write "key" *, select * "open key combination" , then open the key binding page, which is a good interface for ** keybindings.json . You can open keybindings.json in the same way and select "open keyboard shortcut file" (instead of "open keyboard shortcut" ). See if you have never seen. But here I will go with a good interface, also know that you can open this Going File> Preference> Keyboard Shortcut .
In the key binding window, in the search bar, past pyPasteIndent.pasteAndIndent , then click the + button to add a shortcut and create a key binding.
The image below shows how this is done:
source share