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.
In my case "EditorConfig for VS Code" extention is overriding VSCode settings. If you have it installed, then check .editorconfig file in the root folder of the project.
Here is an example config. The "indent_size" sets the number of spaces for a tab.
Code Formatting Shortcut:
VSCode on Windows - Shift + Alt + F
VSCode on MacOS - Shift + Option + F
VSCode on Ubuntu - Ctrl + Shift + I
You can also customize this shortcut using preference setting if needed.
column selection with keyboard Ctrl + Shift + Alt + Arrow
In the toolbar in the bottom right corner you will see a item that looks like the following: 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.tabSize
andeditor.insertSpaces
settings in either User Settings or Workspace Settings depending on your needsAdding on: yes, you can use the bottom-right UI to configure the space settings. But if you have existing code that's not formatted to the new spacing, then you can right-click anywhere within the file and click Format Document. Took me a while to figure this out until I stumbled on this issue.
Format Document menu
Problem: The accepted answer does not actually fix the indentation in the current document.
Solution: Run
Format Document
to re-process the document according to current (new) settings.Problem: The HTML docs in my projects are of type "Django HTML" not "HTML" and there is no formatter available.
Solution: Switch them to syntax "HTML", format them, then switch back to "Django HTML."
Problem: The HTML formatter doesn't know how to handle Django template tags and undoes much of my carefully applied nesting.
Solution: Install the Indent 4-2 extension, which performs indentation strictly, without regard to the current language syntax (which is what I want in this case).
To change the indentation based on programming language, follow one of these ways:
Add this to your settings (Ctrl+,):
(example for TypeScript specific settings):
OR
workbench.action.configureLanguageBasedSettings
)See also: VS Code Docs