I just started using VSCODE and faced with an annoyance every time I paste in YAML code in an existing YML file. Basically the editor seems to auto format the document and in doing so messes up the significant spaces in the document. This causes builds in Azure Devops to break. Although VS code formats the document nicely into collapsible regions, the formatting annoyance makes it hard to use. Any help would be appreciated.
BEFORE:
AFTER:
VS Code has great support for source code formatting. The editor has two explicit format actions: Format Document (Ctrl+Shift+I) - Format the entire active file. Format Selection (Ctrl+K Ctrl+F) - Format the selected text.
It provides YAML validation, error detection, document outlining, auto-completion, hover support, plus syntax checking for Kubernetes YAML files.
The suggested syntax for YAML files is to use 2 spaces for indentation, but YAML will follow whatever indentation system that the individual file uses. Indentation of two spaces works very well for SLS files given the fact that the data is uniform and not deeply nested.
I fixed this by changing editor.autoIndent
settings for yaml
and dockercompose
language
"[yaml]": {
"editor.autoIndent": "advanced"
},
"[dockercompose]": {
"editor.autoIndent": "advanced"
}
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