Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YAML file formatting in VSCODE

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:

BEFORE


AFTER: enter image description here

like image 676
Abhijeet Patel Avatar asked May 23 '20 20:05

Abhijeet Patel


People also ask

How do I change the format of a file in Visual Studio Code?

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.

Does Visual Studio Code support YAML?

It provides YAML validation, error detection, document outlining, auto-completion, hover support, plus syntax checking for Kubernetes YAML files.

How do I correct an indentation in YAML?

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.


1 Answers

I fixed this by changing editor.autoIndent settings for yaml and dockercompose language

"[yaml]": {
  "editor.autoIndent": "advanced"
},
"[dockercompose]": {
  "editor.autoIndent": "advanced"
}
like image 164
ahmadali shafiee Avatar answered Sep 17 '22 15:09

ahmadali shafiee