Right now I am using
set autoindent
when I edit Yaml files in Vim, and it works okay by just copying the previous line's indent when you start a new line. I can't help but feel like it could be a little smarter, though. What would be great is if starting a new line after
foo: "bar"
could keep the same indent level, but starting a line after
foo:
would add an additional level of indent.
Basically, for YAML file it instructs Vim to: Use 2 spaces for indentation. Use spaces instead of tabs. Skip re-indenting lines after inserting a comment character ( # ) at the beginning of a line, or a colon.
Use spaces for indentationedit Indentation is meaningful in YAML. Make sure that you use spaces, rather than tab characters, to indent sections. In the default configuration files and in all the examples in the documentation, we use 2 spaces per indentation level.
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.
Xavier inspired me to hack at this a bit, and I came up with my own little indent script for Yaml. It doesn't handle any of the more advanced Yaml features, but it does what I originally asked for.
To use this, you can just drop it into ~/.vim/after/ftplugin/yaml.vim
(assuming you are using set ftplugin on
).
Specific indentation rules are stored on a language basis in :$VIMRUNTIME\indent\foo.vim
for language foo
.
On my default installation, I have got ruby.vim
, haml.vim
and many other but no yaml.vim
.
You could create an indent\yaml.vim
to get the indentation rules you want. I have quickly tried to search online if something similar was available but I have not find anything.
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