Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change indentation in Visual Studio Code?

For every typescript file visual studio code uses an auto indentation of 8 spaces. This is a bit too much for my taste but I can't find where to change it.

Maybe it's available as a setting but under a different name as I can't find anything related to indentation.

UPDATE

I'm currently using the Prettier code formatter and that solves all formatting problems by auto formatting on save (if there is no syntax error)

like image 343
HMR Avatar asked Dec 09 '15 08:12

HMR


People also ask

How do I reduce indentation code in Visual Studio?

“shortcut to remove indent vscode” Code Answer and also indent backward using Shift + TAB.

How do you change the indentation of multiple lines in VS code?

“how to indent multiple lines in vscode” Code Answer's you can also indent a whole section by selecting it and clicking TAB. and also indent backward using Shift + TAB.


2 Answers

In the toolbar in the bottom right corner you will see a item that looks like the following: enter image description here After clicking on it you will get the option to indent using either spaces or tabs. After selecting your indent type you will then have the option to change how big an indent is. In the case of the example above, indentation is set to 4 space characters per indent. If tab is selected as your indentation character then you will see Tab Size instead of Spaces

If you want to have this apply to all files and not on an idividual file basis, override the Editor: Tab Size and Editor: Insert Spaces settings in either User Settings or Workspace Settings depending on your needs

Edit 1

To get to your user or workspace settings go to Preferences -> Settings. Verify that you are on the User or Workspace tab depending on your needs and use the search bar to locate the settings. You may also want to disable Editor: Detect Indentation as this setting will override what you set for Editor: Insert Spaces and Editor: Tab Size when it is enabled

like image 99
elliot-j Avatar answered Sep 21 '22 00:09

elliot-j


You can change this in global User level or Workspace level.

Open the settings: Using the shortcut Ctrl , or clicking File > Preferences > Settings as shown below.

Settings on VS Code menu

Then, do the following 2 changes: (type tabSize in the search bar)

  1. Uncheck the checkbox of Detect Indentation
  2. Change the tab size to be 2/4 (Although I strongly think 2 is correct for JS :))

vscode set tabsize

like image 36
Xin Avatar answered Sep 18 '22 00:09

Xin