|
| 1 | +" Vim syntax file |
| 2 | +" Language: Ansible YAML/Jinja templates |
| 3 | +" Maintainer: Dave Honneffer <[email protected]> |
| 4 | +" Last Change: 2015.09.06 |
| 5 | + |
| 6 | +if exists("b:current_syntax") |
| 7 | + finish |
| 8 | +endif |
| 9 | + |
| 10 | +if !exists("main_syntax") |
| 11 | + let main_syntax = 'yaml' |
| 12 | +endif |
| 13 | + |
| 14 | +let b:current_syntax = '' |
| 15 | +unlet b:current_syntax |
| 16 | +runtime! syntax/yaml.vim |
| 17 | + |
| 18 | +let b:current_syntax = '' |
| 19 | +unlet b:current_syntax |
| 20 | +syntax include @Yaml syntax/yaml.vim |
| 21 | + |
| 22 | +let b:current_syntax = '' |
| 23 | +unlet b:current_syntax |
| 24 | +syntax include @Jinja syntax/jinja2.vim |
| 25 | + |
| 26 | +" Jinja |
| 27 | +" ================================ |
| 28 | + |
| 29 | +syn cluster jinjaSLSBlocks add=jinjaTagBlock,jinjaVarBlock,jinjaComment |
| 30 | +" https://github.com/mitsuhiko/jinja2/blob/6b7c0c23/ext/Vim/jinja.vim |
| 31 | +syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks |
| 32 | +syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks |
| 33 | +syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,@jinjaSLSBlocks |
| 34 | +highlight link jinjaVariable Constant |
| 35 | +highlight link jinjaVarDelim Delimiter |
| 36 | + |
| 37 | +" YAML |
| 38 | +" ================================ |
| 39 | + |
| 40 | +" Reset some YAML to plain styling |
| 41 | +" the number 80 in Ansible isn't any more important than the word root |
| 42 | +highlight link yamlInteger Ignore |
| 43 | +highlight link yamlBool Ignore |
| 44 | +highlight link yamlFlowString Ignore |
| 45 | +" but it does make sense we visualize quotes easily |
| 46 | +highlight link yamlFlowStringDelimiter Delimiter |
| 47 | + |
| 48 | +fun! s:attribute_highlight(attributes) |
| 49 | + if a:attributes =~ 'a' |
| 50 | + syn match ansible_attributes "\v\w+\=" containedin=yamlPlainScalar |
| 51 | + else |
| 52 | + syn match ansible_attributes "\v^\s*\w+\=" containedin=yamlPlainScalar |
| 53 | + endif |
| 54 | + if a:attributes =~ 'n' |
| 55 | + highlight link ansible_attributes Ignore |
| 56 | + elseif a:attributes =~ 'd' |
| 57 | + highlight link ansible_attributes Comment |
| 58 | + else |
| 59 | + highlight link ansible_attributes Structure |
| 60 | + endif |
| 61 | +endfun |
| 62 | + |
| 63 | +if exists("g:ansible_attribute_highlight") |
| 64 | + call s:attribute_highlight(g:ansible_attribute_highlight) |
| 65 | +else |
| 66 | + call s:attribute_highlight('ad') |
| 67 | +endif |
| 68 | + |
| 69 | +if exists("g:ansible_name_highlight") |
| 70 | + syn keyword ansible_name name containedin=yamlBlockMappingKey contained |
| 71 | + if g:ansible_name_highlight =~ 'd' |
| 72 | + highlight link ansible_name Comment |
| 73 | + else |
| 74 | + highlight link ansible_name Underlined |
| 75 | + endif |
| 76 | +endif |
| 77 | + |
| 78 | +syn keyword ansible_debug_keywords debug containedin=yamlBlockMappingKey contained |
| 79 | +highlight link ansible_debug_keywords Debug |
| 80 | + |
| 81 | +syn match ansible_with_keywords "\vwith_.+" containedin=yamlBlockMappingKey contained |
| 82 | +syn keyword ansible_special_keywords include until retries delay when only_if become become_user block rescue always notify containedin=yamlBlockMappingKey contained |
| 83 | +highlight link ansible_with_keywords Statement |
| 84 | +highlight link ansible_special_keywords Statement |
| 85 | + |
| 86 | +let b:current_syntax = "ansible" |
0 commit comments