Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Vim Settings for Working With YAML [Snippet]

DZone's Guide to

Vim Settings for Working With YAML [Snippet]

Let's take a look at a short tutorial that gives an explanation of the vim settings for working with YAML.

· Integration Zone ·
Free Resource

How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.

Having managed to avoid YAML until quite recently, my vim installation wasn't well set up at all for working with it. It needs more config settings than plugins, so I thought I'd write down what I found helpful. I'm using it quite a lot now I'm working with OAS (used to be Swagger) API definitions.

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.

Make your mark on the industry’s leading annual report. Fill out the State of API Integration 2019 Survey and receive $25 to the Cloud Elements store.

Topics:
integration ,tutorial ,yaml ,vim settings

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}