Skip to content
Latchkey

YAML Syntax Cheat Sheet: Types, Anchors & Multiline

YAML types, multiline blocks, and anchors in one reference (plus the gotchas).

The syntax you use writing CI and config YAML, and the traps to avoid.

Structure

config.yaml
key: value          # mapping
list:               # sequence
  - one
  - two
nested:
  inner: value
inline_list: [a, b]
inline_map: {x: 1}

Multiline strings

BlockBehavior
| (literal)Keeps newlines
> (folded)Folds newlines to spaces
|- / >-Strip trailing newline
|+ / >+Keep trailing newlines

Anchors & aliases

anchors
defaults: &defaults
  retries: 3
  timeout: 30
job_a:
  <<: *defaults      # merge
  name: a

Gotchas

PitfallFix
Tabs for indentUse spaces only
yes/no/on/off parsed as boolQuote "no" if you mean string
Unquoted version 1.0 -> floatQuote "1.0"
Leading 0 -> octal/stringQuote it

Key takeaways

  • Indentation is spaces only - tabs are a hard error.
  • | keeps newlines; > folds them into spaces.
  • Quote ambiguous scalars like no, yes, on, and versions.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →