How do I break a string over multiple lines?

前端 未结 9 1386
有刺的猬
有刺的猬 2020-11-22 01:06

In YAML, I have a string that\'s very long. I want to keep this within the 80-column (or so) view of my editor, so I\'d like to break the string. What\'s the syntax for this

9条回答
  •  眼角桃花
    2020-11-22 01:16

    For situations were the string might contain spaces or not, I prefer double quotes and line continuation with backslashes:

    key: "String \
      with long c\
      ontent"
    

    But note about the pitfall for the case that a continuation line begins with a space, it needs to be escaped (because it will be stripped away elsewhere):

    key: "String\
      \ with lon\
      g content"
    

    If the string contains line breaks, this needs to be written in C style \n.

    See also this question.

提交回复
热议问题