-1

I have an entry in my yaml file that looks like this

my_key:['short string', 'thisisaverylongstringthatcontains.,specialcharacterssoI havetousequotes,andI wanttobreakintomultiplelines']

My very long string can't contain spaces, and I am worried if I simply use newline, it will get converted to space. What is the cleanest, simplest way to break down that second string across multiple lines for easier readability and convenience?

Baron Yugovich
  • 3,843
  • 12
  • 48
  • 76
  • It's an exact duplicate. You can use a string quoted with `>` anywhere YAML expects a string. Just because you have a list of strings doesn't impact your ability to use that syntax. – larsks Oct 15 '18 at 00:53
  • Yes, actually; you'd be surprised at how often that happens around here. – larsks Oct 15 '18 at 00:55
  • 1
    Your question is answered by [this answer to the same duplicate question](https://stackoverflow.com/a/43354815/147356). – larsks Oct 15 '18 at 00:58
  • 1
    "So how did you expect me to find this answer near the bottom of the page?" Having had several people point out that this question was a duplicate, I expected you, as someone familiar with the site, to thoroughly read through the answers there. – larsks Oct 15 '18 at 01:02

1 Answers1

0
key  : ['short string', "this is a very long string 
                         that I want to break into
                         multiple lines"]

Have you tried just inserting a newline? This is valid YAML.

If you don't want spaces, add \ to the end of each line.

key  : ['short string', "this is a very long string\
                         that I want to break into\
                         multiple lines"]
Sean Pianka
  • 2,157
  • 2
  • 27
  • 43