Insert VS code for Python

How to enable indentation in VS code?

I am trying to learn Python (new to programming) and need an auto report. It worked with the first version I tried, but after the colon ( : it no longer backs off. How can I set it to indent automatically?

+9
source share
5 answers

You can install the Python VSCode extension, which will provide intellisense, autocomplete, code formatting, and debugging. Here is more information about the Python extension, here

+8
source

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:

enter image description here

+8
source

I ran into similar problems while editing. Select the lines of code you want to use and press CTRL + ] in windows or CMD + ] on Mac.
You can change the size of the indent in the settings. Look for tab size in settings. I use 2 by the way.

+1
source

I ran into similar issues when migrating from PyCharm. The Python Indent extension , which is available on the Visual Studio Code market, works great for me.

0
source

A simple solution! Click the tab size in the lower right corner and select "convert indents to tabs" or "convert indents to spaces" according to your requirements.

0
source

Source: https://habr.com/ru/post/1012151/


All Articles