Instantly share code, notes, and snippets.

What would you like to do?
Dumb-smart indentation for Yaml
" Vim indent file
" Language: Yaml
" Author: Ian Young
" Get it bundled for pathogen:
if exists("b:did_indent")
"runtime! indent/ruby.vim
"unlet! b:did_indent
let b:did_indent = 1
setlocal autoindent sw=2 et
setlocal indentexpr=GetYamlIndent()
setlocal indentkeys=o,O,*<Return>,!^F
function! GetYamlIndent()
let lnum = v:lnum - 1
if lnum == 0
return 0
let line = substitute(getline(lnum),'\s\+$','','')
let indent = indent(lnum)
let increase = indent + &sw
if line =~ ':$'
return increase
return indent
" vim:set sw=2:

This comment has been minimized.

jacqueswww commented Oct 25, 2015

Thanks !


This comment has been minimized.

ladislas commented May 29, 2017

that's amazing, thanks so much! :)


This comment has been minimized.

mlongval commented Aug 16, 2018

Thanks for this. Helps a lot.

modified for "set sw=4" (personal preferences)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment