-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaml.vim
65 lines (55 loc) · 1.32 KB
/
yaml.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function! GetYamlPath(line)
let lnum = a:line
let curr_line = getline(lnum)
if curr_line =~# '^\s*\(#.*\)\?$' " comments and blank lines
return ''
endif
let islist = 0
let curr_indent = indent(lnum)
if curr_line =~# '^\s*-\s'
let islist = 1
let curr_indent += 2
endif
let trig_indent = curr_indent
let yaml_key = matchstr(curr_line, '^\s*-\?\s*\zs\S\{-}\ze:') " non-greedy
if yaml_key =~# '\.'
let yaml_key = '"' .. yaml_key .. '"'
endif
let yaml_path = yaml_key
while curr_indent > 0
let lnum -= 1
if lnum == 0
return ''
endif
let curr_line = getline(lnum)
if curr_line =~# '^\s*\(#.*\)\?$' " comments and blank lines
continue
endif
let list_indicator = ''
if islist
let list_indicator = '[]'
endif
let islist = 0
let curr_indent = indent(lnum)
if curr_line =~# '^\s*-\s'
let islist = 1
let curr_indent += 2
endif
if curr_indent >= trig_indent
continue
endif
let trig_indent = curr_indent
let yaml_key = matchstr(curr_line, '^\s*-\?\s*\zs\S\{-}\ze:') " non-greedy
if yaml_key =~# '\.'
let yaml_key = '"' .. yaml_key .. '"'
endif
let yaml_path = yaml_key .. list_indicator .. '.' .. yaml_path
endwhile
return yaml_path
endfunction
augroup YamlPath
au!
if &filetype =~# 'yaml'
autocmd CursorMoved <buffer> redraw | echo GetYamlPath(line('.'))
endif
aug END