How to force VS Code to always use the same level of indentation for ALL files?

Viewed 37

I have problems with indentations of VS Code.

Different file types, different indentations.

Same file types, different indentations. Completely unpredictable.

For example, two docker-compose.yml files. One has 2-space indentation. The other 4-space indentation.

How can I force VS Code to use the same indentation, for ALL files, regardless of type.

1 Answers

In VS Code to format your code you have few options. Format manually, right click and select format document or SHIFT+ALT+F. You can also use VS Code settings like format on save (editor.formatOnSave), to enable autoformat on saving files.

You have project based formatting settings using .editorconfig file in the root of project. Install EditorConfig for VS Code extension to enable that. The other option would be to use Prettier, check Prettier - Code formatter extension. Follow, extensions description for details on how to configure your formatting settings for each.

Related