set shiftwidth=2 set tabstop=2 set expandtab function! GetAncestors(line) if(indent(a:line) == 0 && a:line == 1) return '' endif if(indent(a:line) == 0 && a:line > 1) if(getline(a:line) !~ '^\s*$') " not an empty line return '' else " sometimes there are newlines within a multiline key return GetAncestors(a:line-1) " return ancestors of previous line endif endif let lowerIndent = indent(a:line)-1 " check if line is part of a list let isList = '' if(getline(a:line) =~# '^\s*-') let isList = '[]' " find the first key above this in the file that has is not a list member let lastKeyLine = search('^\s\{0,'.indent(a:line).'}[^-]\S\+:', 'bnW') else " find the first key above this in the file that has a lower indent or a " containing list member let lastKeyLine = search('^\s\{0,'.lowerIndent.'}\(\S\+\|-\s\S\+\):', 'bnW') let lastKeyLineContent = getline(lastKeyLine) " check if the containing key is not a member of the same object if(lastKeyLineContent =~# ':\s.\+$' && lastKeyLineContent =~# '^\s*-') let lastKeyLine = search('^\s\{0,'.lowerIndent.'}\(\S\+\|-\s\S\+\):\s*$', 'zbnW') let isList = '[]' endif endif let key = matchstr(getline(lastKeyLine), '\s*[\-]\?\s*\zs.\+\ze:').isList if(indent(lastKeyLine) > 0) return GetAncestors(lastKeyLine).' . '.key endif return key endfunction augroup YamlRevealer au! if(&filetype =~# 'yaml') autocmd CursorMoved redraw | echo GetAncestors(line('.')) endif aug END