Vim settings for working with YAML
Let’s start with the easy bit: I’m using the yaml-vim plugin. This seems to do a decent job of syntax highlighting, really helping to spot mistakes!
I added a bunch of configuration to my .vimrc
also:
" add yaml stuffs
au! BufNewFile,BufReadPost *.{yaml,yml} set filetype=yaml foldmethod=indent
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
By setting the foldmethod
to indent, I get a fold on an increase in indentation levels, which really helps to just expand the bits I’m working on and generally be able to find my way around a file (Pythonistas may find this setting useful since Python works on a similar indentation basis).
Most of the rest of the configuration is around indentation. Yaml does not allow tabs, and indents are multiples of two spaces, so I’ve set the expandtab
value here and also set tabstop/soft tabstop (ts
and sts
), and shiftwidth (sw
) to 2.
Bonus pro tip: Try openapi-spec-validator
to check your OAS documents are making sense.
This is just great: by default vim has broken yaml handling. Plugin + conf = love, thanks!
Hey,
Now it is not so much pain while working with yml , even better kind of like it, yeah I know – strange :D
thanks a lot
Thanks! Saved me some time.
In 2022 on Ubuntu 21.10, vim installs loads of modules all of which seem to break anything I put in ~/.vimrc or .vim/vimrc or /etc/vim/
Amazingly bad distribution of vim.