diff options
Diffstat (limited to '.vim/ftplugin')
-rw-r--r-- | .vim/ftplugin/php.vim | 3 | ||||
-rw-r--r-- | .vim/ftplugin/yaml.vim | 49 |
2 files changed, 52 insertions, 0 deletions
diff --git a/.vim/ftplugin/php.vim b/.vim/ftplugin/php.vim new file mode 100644 index 0000000..b8df966 --- /dev/null +++ b/.vim/ftplugin/php.vim @@ -0,0 +1,3 @@ +set shiftwidth=4 +set tabstop=4 +set expandtab diff --git a/.vim/ftplugin/yaml.vim b/.vim/ftplugin/yaml.vim index 0c0c07f..ae4ce66 100644 --- a/.vim/ftplugin/yaml.vim +++ b/.vim/ftplugin/yaml.vim @@ -1,3 +1,52 @@ 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 <buffer> redraw | echo GetAncestors(line('.')) + endif +aug END |