Ian Greenleaf Young
Ian Greenleaf Young

Reputation: 1958

How do I get great auto indenting with Vim and Yaml?

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.

Upvotes: 21

Views: 15458

Answers (2)

Ian Greenleaf Young
Ian Greenleaf Young

Reputation: 1958

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).

Upvotes: 13

Xavier T.
Xavier T.

Reputation: 42238

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.

Upvotes: 4

Related Questions