I want VSCode on my Mac to use 4 spaces instead of 2 when I select Format Document. This is what I have on my User Settings:
{
"editor.fontFamily": "Andale Mono",
"editor.fontSize": 13,
"editor.renderWhitespace": "all",
"editor.tabSize": 4,
"[dart]": {
"editor.tabSize": 4,
"editor.detectIndentation": false
},
"workbench.colorTheme": "Material Theme",
"materialTheme.fixIconsRunning": false,
"workbench.iconTheme": "eq-material-theme-icons"
}
However when I format the document, it does not respect the 4 spaces tab. It uses 2.
Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately.
Automatically formatting code in VS Code To automatically format the code in the current source code window, right-click in the code window and select Format Document . You can add a keyboard shortcut to this VS Code Preferences. To automatically format code whenever you save a file, set the editor.
In VS Code you can access the editor's tab size settings by pressing Command+Comma (Mac) or Ctrl+Comma (PC), and typing tabsizing . You can edit settings for regular and pinned tabs. Currently there are two options for sizing editor tabs: fit and shrink .
Use the dart format command to replace the whitespace in your program with formatting that follows Dart guidelines. This is the same formatting that you can get when using an IDE or editor that has Dart support. For more information about this and other dart commands, see the Dart command-line tool page.
This is a limitation of the Dart plugin for VS Code. It uses the official dart_style
formatter which only supports formatting with spaces (the same as running dartfmt
).
If you'd like to see a more flexible formatter, please put a ThumbsUp on this GitHub issue:
https://github.com/Dart-Code/Dart-Code/issues/914
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