Home > Software design >  VSC putting in amount of spaces as level of indentation on newline
VSC putting in amount of spaces as level of indentation on newline

Time:10-17

I was just setting up visual studio code so that my python code uses tabs for indentation. Now when I press enter, instead of VSC putting in the correct amount of tabs to stay in the indent, it converts them to spaces. I have seen so many posts that deal with the opposite problem but not with this one. Has this happened to anyone?

example:

counter = 0
while True:
    print(Hello World)
    counter =1
    if counter == 1:
        print(counter)
  #now when I pressed enter it added only two spaces instead of two tabs

My tab size is set to 4 and I have tried turning on/off the insert spaces setting, and Detect Indentation. Also I have tried clicking on the tab size in the right corner and using the menu there, but nothing has fixed this.

CodePudding user response:

Open your settings.

enter image description here

  1. Set the Editor: Auto Indent full

enter image description here

2.Set the Editor: Tab Size 4

enter image description here

CodePudding user response:

Option 1

  1. You can choose to indent using spaces or tabs using the command pallete Ctrl Shift P or ⌘ Shift P for mac.

  2. Writing indent, gives the following options: Indentation options from command pallete

  3. Choose Convert Indentation Tabs. This will fix the problem.

Option 2

You can update the indentation for the VS Code by following these steps:

Select Spaces from bottom right

Select spaces from bottom right

Choose Indentation type

Choose whether you want to indent using space or tab (tab here). Select indentation type

Choose tab size

The tab size is the number of columns (characters) tab will occupy. You can select that. Choose tab size

  • Related