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?
Indentation. The suggested syntax for YAML files is to use 2 spaces for indentation, but YAML will follow whatever indentation system that the individual file uses. Indentation of two spaces works very well for SLS files given the fact that the data is uniform and not deeply nested.
Start in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.
In YAML block styles, structure is determined by indentation. In general, indentation is defined as a zero or more space characters at the start of a line. To maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently.
In order to get the nice 2-space YAML as the default when I hit carriage return after the colon, I added this to my .vimrc
:
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
This also plays nice with the dash for the OP's expected result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With