Glueon Glueon - 1 month ago 30
YAML Question

Wrong indentation when editing Yaml in Vim

Vim does not seem to correctly react at a dash symbol in YAML files therefore breaking the format.

For example I have a block which should look like this:

handlers:
- name: restart exim4
service: name=exim4 state=restarted


When I finish typing
restart exim4
and type
service:
Vim reindents my final
service
line:

handlers:
- name: restart exim4
service: name=exim4 state=restarted


So clearly Vim tries to align sentences column-wise but that's not what is needed in YAML. I want to create an array with two values.

How to fix that?

Answer

Install this plugin:

https://github.com/chase/vim-ansible-yaml

It is made with Ansible in mind, but in theory it will work with all kinds of YAML files. You will have to :set filetype=ansible unfortunately, if you are not working with ansible related files.

Comments