The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.
Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.
The number of spaces to use for formatting is taken from a different location. I'm using version 1.0 and this is what I've done to fix it (I'm assuming your using spaces instead of tabs):
At the bottom of the editor on the right hand click "Spaces: #":
Then a menu will appear up top. Select "Indent Using Spaces":
Finally you can select by how many spaces you want your files to be indented.
The next time you format a file you should be able to get the spacing you configured.
Visual Studio Code detects the current indentation per default and uses this - ignoring the .editorconfig
Set also "editor.detectIndentation" to false
(Files -> Preferences -> Settings)
If @Maleki's answer isn't working for you, check and see if you have an .editorconfig
file in your project folder.
For example the Angular CLI generates one with a new project that looks like this
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
Changing the indent_size
here is required as it seems it will override anything in your .vscode
workspace or user settings.
If you're using a plugin (in my case Vetur, for vue.js), these may set their own tab formatting settings.
Open your settings, search for "format" and look through relevant plugin settings that may be overwriting the global tab format. This worked for me; once I updated Vetur tab settings to match my preference (4-size tabs in my case), formatting .vue documents started to work properly:
For myself, this problem was caused by using the prettier
VSCode plugin without having a prettier config file in the workspace.
Disabling the plugin fixed the problem. It could have also probably been fixed by relying on the prettier config.
the settings below solved my issue
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 2,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With