Deleting Leading Spaces in YAML

My configuration.yaml is starting to get outrageously long so I was thinking of splitting the file into multiple pieces using the !include function for my automations, scripts, scenes, etc…

Because I’ve set everything up in configuration.yaml, my spacing is like so:

scene:
  - name: Scene 1
    entities:
      cover.entry_entry_left_shade:
        position: 100
      cover.entry_entry_right_shade:
        position: 100
      cover.library_library_shade:
        position: 100

But I need to change it to:

Configuration.yaml
scene: !include scenes.yaml

Scenes.yaml

- name: Scene 1
  entities:
    cover.entry_entry_left_shade:
      position: 100
    cover.entry_entry_right_shade:
      position: 100
    cover.library_library_shade:
      position: 100

So I have to delete the leading two spaces of every line for every scene to get it to work in the new scenes.yaml (at least that’s my understanding). Does anyone know of an easy way to do that aside from manually deleting it from each line?

I usually pass such cases through word where I replace new line & 2 spaces with new line

if you’re using the Configurator panel in HA and on a Mac, you can hold down the option key on your keyboard and select characters at the same index on multiple lines. Try it by holding down option, then click & drag in the editor. (Most desktop code editors implement this as well)

If you’re on Windows or Linux, it’s probably a different keyboard key, not sure which :slight_smile:

notepad++ will let you work with a column and do that

Visual Studio Code (and many other editors) will let you highlight an entire section and press “shift + tab” to un-indent an entire block.

2 Likes

Yep, most code editors have that feature. In fact many popular editors (notepad++ and atom come to mind) don’t even require a shift; you just highlight the section, hit tab, and everything highlighted moves over.

Tab adds indentation, Shift+Tab removes indentation.

3 Likes

You don’t need to do that. Yaml doesn’t care. Just leave the spaces in.

Thank you all for your help! I use a Mac with Atom and @truglodite & @fanaticDavid’s suggestion of highlighting and then Shift + Tab moved everything back perfectly. Thanks!

I believe atom works in a similar fashion to VScode, if so you can also hold Left ALT+Shift and Right Mousebutton to drag and select a column only, you can then use space, tab, delete, backspace or even type on all those lines at the same time.

looks like your suggestion was completely ignored. And it was the easiest of the whole bunch. :laughing:

But yes, as long as everything in the file has consistent indentation it pretty much doesn’t matter. I’ve used it both ways (with two spaces indentation on the first column and with no indentation at all on the first column) and both ways work fine with no complaints.

Neither of you are acknowledging the OCD purists in 80% of our membership (incl me ! ) :rofl:

3 Likes

:man_shrugging: I like to take the easiest path

Yep! Yaml don’t care

1 Like