Browse Source

vim: ++ansible-vim

master
Maxim Likhachev 6 years ago
parent
commit
63676fd5d7
  1. 21
      etc/soft/vim/vim/+plugins/ansible-vim/LICENSE
  2. 135
      etc/soft/vim/vim/+plugins/ansible-vim/README.md
  3. 1
      etc/soft/vim/vim/+plugins/ansible-vim/UltiSnips/.gitignore
  4. 35
      etc/soft/vim/vim/+plugins/ansible-vim/UltiSnips/README.md
  5. 109
      etc/soft/vim/vim/+plugins/ansible-vim/UltiSnips/generate.py
  6. 40
      etc/soft/vim/vim/+plugins/ansible-vim/ftdetect/ansible.vim
  7. 6
      etc/soft/vim/vim/+plugins/ansible-vim/ftplugin/ansible.vim
  8. 9
      etc/soft/vim/vim/+plugins/ansible-vim/ftplugin/ansible_hosts.vim
  9. 59
      etc/soft/vim/vim/+plugins/ansible-vim/indent/ansible.vim
  10. 104
      etc/soft/vim/vim/+plugins/ansible-vim/syntax/ansible.vim
  11. 31
      etc/soft/vim/vim/+plugins/ansible-vim/syntax/ansible_hosts.vim
  12. 97
      etc/soft/vim/vim/+plugins/ansible-vim/syntax/jinja2.vim
  13. 31
      etc/soft/vim/vim/+plugins/ansible-vim/syntax/jinja2.vim_LICENSE

21
etc/soft/vim/vim/+plugins/ansible-vim/LICENSE

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Dave Honneffer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

135
etc/soft/vim/vim/+plugins/ansible-vim/README.md

@ -0,0 +1,135 @@
## introduction
This is a vim syntax plugin for Ansible 2.x, it supports YAML playbooks, Jinja2 templates, and Ansible's `hosts` files.
- YAML playbooks are detected if:
- they are in the `group_vars` or `host_vars` folder
- they are in the `tasks`, `roles`, or `handlers` folder and have either a *.yml* or *.yaml* suffix
- they are named `playbook.y(a)ml`, `site.y(a)ml`, or `main.y(a)ml`
- Jinja2 templates are detected if they have a *.j2* suffix
- Files named `hosts` will be treated as Ansible hosts files
You can also set the filetype to `yaml.ansible`, `*.jinja2`, or `ansible_hosts` if auto-detection does not work (e.g. `:set ft=yaml.ansible` or `:set ft=ruby.jinja2`). **Note**: If you want to detect a custom pattern of your own, you can easily add this in your `.vimrc` using something like this:
```vim
au BufRead,BufNewFile */playbooks/*.yml set filetype=yaml.ansible
```
If you want to override the default file type detection you can easily do this in your `.vimrc`. For example if you use YAML syntax for `hosts` include something like this:
```vim
augroup ansible_vim_fthosts
autocmd!
autocmd BufNewFile,BufRead hosts setfiletype yaml.ansible
augroup END
```
This plugin should be quite reliable, as it sources the original formats and simply modifies the highlights as appropriate. This also enables a focus on simplicity and configurability instead of patching bad syntax detection.
##### examples (with [solarized](https://github.com/altercation/vim-colors-solarized) colorscheme)
Bright (and selective highlight) | Dim
:-----------------------------------:|:-------------------------:
![](http://i.imgur.com/whBOZZK.png) | ![](http://i.imgur.com/XS0T00e.png)
##### installation
Use your favorite plugin manager, or try [vim-plug](https://github.com/junegunn/vim-plug) if you're looking for a really nice one!
**vim-plug:** `Plug 'pearofducks/ansible-vim'`
**vim-plug with post-update hook:** `Plug 'pearofducks/ansible-vim', { 'do':
'cd ./UltiSnips; ./generate.py' }`
*Note: `generate.py` requires Ansible 2.4 or later.*
**vundle:** `Plugin 'pearofducks/ansible-vim'`
**pathogen:** `git clone https://github.com/pearofducks/ansible-vim ~/.vim/bundle/ansible-vim`
**Arch Linux:** Package [ansible-vim-git](https://aur.archlinux.org/packages/ansible-vim-git/) available on AUR
## options
##### g:ansible_unindent_after_newline
`let g:ansible_unindent_after_newline = 1`
When this variable is set, indentation will completely reset (unindent to column 0) after two newlines in insert-mode. The normal behavior of YAML is to always keep the previous indentation, even across multiple newlines with no content.
##### g:ansible_yamlKeyName
`let g:ansible_yamlKeyName = 'yamlKey'`
This option exists to provide additional compatibility with [stephpy/vim-yaml](https://github.com/stephpy/vim-yaml).
##### g:ansible_attribute_highlight
`let g:ansible_attribute_highlight = "ob"`
Ansible modules use a `key=value` format for specifying module-attributes in playbooks. This highlights those as specified. This highlight option is also used when highlighting key/value pairs in `hosts` files.
Available flags (bold are defaults):
- **a**: highlight *all* instances of `key=`
- o: highlight *only* instances of `key=` found on newlines
- **d**: *dim* the instances of `key=` found
- b: *brighten* the instances of `key=` found
- n: turn this highlight off completely
##### g:ansible_name_highlight
`let g:ansible_name_highlight = 'd'`
Ansible modules commonly start with a `name:` key for self-documentation of playbooks. This option enables/changes highlight of this.
Available flags (this feature is off by default):
- d: *dim* the instances of `name:` found
- b: *brighten* the instances of `name:` found
##### g:ansible_extra_keywords_highlight
`let g:ansible_extra_keywords_highlight = 1`
*Note:* This option is enabled when set, and disabled when not set.
Highlight the following additional keywords in playbooks: `register always_run changed_when failed_when no_log args vars delegate_to ignore_errors`
By default we only highlight: `include until retries delay when only_if become become_user block rescue always notify`
##### g:ansible_normal_keywords_highlight
`let g:ansible_normal_keywords_highlight = 'Constant'`
Accepts any syntax group name from `:help E669` - e.g. _Comment_, _Constant_, and _Identifier_
*Note:* Defaults to 'Statement' when not set.
This option change the highlight of the following common keywords in playbooks: `include until retries delay when only_if become become_user block rescue always notify`
##### g:ansible_with_keywords_highlight
`let g:ansible_with_keywords_highlight = 'Constant'`
Accepts any syntax group-name from `:help E669` - e.g. _Comment_, _Constant_, and _Identifier_
*Note:* Defaults to 'Statement' when not set.
This option changes the highlight of all `with_.+` keywords in playbooks.
##### g:ansible_template_syntaxes
`let g:ansible_template_syntaxes = { '*.rb.j2': 'ruby' }`
Accepts a dictionary in the form of `'regex-for-file': 'filetype'`.
- _regex-for-file_ will receive the full filepath, so directory matching can be done.
- _filetype_ is the root filetype to be applied, `jinja2` will be automatically appended
All files ending in `*.j2` that aren't matched will simply get the `jinja2` filetype.
## bugs, suggestions/requests, & contributions
##### bugs
It's unlikely that there will be bugs in highlighting that don't exist in the core format. Where appropriate these will be fixed in this plugin, but if the problem is with the original syntax we should probably focus on fixing that instead.
Indenting a full document - e.g with `gg=G` - will not be supported and is not a goal of this plugin (unless someone else develops it!). Please do not file a bug report on this.
##### suggestions/requests
Suggestions for improvements are welcome, pull-requests with completed features even more so. :)

1
etc/soft/vim/vim/+plugins/ansible-vim/UltiSnips/.gitignore vendored

@ -0,0 +1 @@
ansible.snippets

35
etc/soft/vim/vim/+plugins/ansible-vim/UltiSnips/README.md

@ -0,0 +1,35 @@
Generate Snippets Based on Ansible Modules
==========================================
A script to generate `UltiSnips` based on ansible code on the fly.
**Note:** Requires Ansible 2.4 or later.
Script parameters
-----------------
There are a couple of optional arguments for the script.
* --output: Output filename (Default: ansible.snippets)
* --style: YAML formatting style for snippets
Choices: multiline (default), dictionary
* --sort: Whether to sort module arguments (default: no)
For Users
---------
We display option description somewhere, however, there are some special formatters in it.
For your reference, we list them here and you can find them under `/ansible/repo/hacking/module_formatter.py`:
* I: Italic
* B: Bold
* M: Module
* U: URL
* C: Const
For Developers
--------------
* `pip install ansible` first
Thanks
------
* Based on (ansible)[https://github.com/ansible/ansible] Awesome Documentation
* Inspired by [bleader/ansible_snippet_generator](https://github.com/bleader/ansible_snippet_generator)

109
etc/soft/vim/vim/+plugins/ansible-vim/UltiSnips/generate.py

@ -0,0 +1,109 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import argparse
import os
import os.path
import ansible.modules
from ansible.utils.plugin_docs import get_docstring
from ansible.plugins.loader import fragment_loader
def get_documents():
for root, dirs, files in os.walk(os.path.dirname(ansible.modules.__file__)):
for f in files:
if f == '__init__.py' or not f.endswith('py'):
continue
documentation = get_docstring(os.path.join(root, f), fragment_loader)[0]
if documentation is None:
continue
yield documentation
def to_snippet(document):
snippet = []
if 'options' in document:
options = document['options'].items()
if args.sort:
options = sorted(options, key=lambda x: x[0])
options = sorted(options, key=lambda x: x[1].get('required', False), reverse=True)
for index, (name, option) in enumerate(options, 1):
if 'choices' in option:
default = option.get('default')
if isinstance(default, list):
prefix = lambda x: '#' if x in default else ''
suffix = lambda x: "'%s'" % x if isinstance(x, str) else x
value = '[' + ', '.join("%s%s" % (prefix(choice), suffix(choice)) for choice in option['choices'])
else:
prefix = lambda x: '#' if x == default else ''
value = '|'.join('%s%s' % (prefix(choice), choice) for choice in option['choices'])
elif option.get('default') is not None and option['default'] != 'None':
value = option['default']
if isinstance(value, bool):
value = 'yes' if value else 'no'
else:
value = "# " + option.get('description', [''])[0]
if args.style == 'dictionary':
delim = ': '
else:
delim = '='
if name == 'free_form': # special for command/shell
snippet.append('\t${%d:%s%s%s}' % (index, name, delim, value))
else:
snippet.append('\t%s%s${%d:%s}' % (name, delim, index, value))
# insert a line to seperate required/non-required fields
for index, (_, option) in enumerate(options):
if not option.get("required"):
if index != 0:
snippet.insert(index, '')
break
if args.style == 'dictionary':
snippet.insert(0, '%s:' % (document['module']))
else:
snippet.insert(0, '%s:%s' % (document['module'], ' >' if len(snippet) else ''))
snippet.insert(0, 'snippet %s "%s" b' % (document['module'], document['short_description']))
snippet.append('')
snippet.append('endsnippet')
return "\n".join(snippet)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'--output',
help='output filename',
default='ansible.snippets'
)
parser.add_argument(
'--style',
help='yaml format to use for snippets',
choices=['multiline', 'dictionary'],
default='multiline'
)
parser.add_argument(
'--sort',
help='sort module arguments',
action='store_true',
default=False
)
args = parser.parse_args()
with open(args.output, "w") as f:
f.writelines(["priority -50\n", "\n", "# THIS FILE IS AUTOMATED GENERATED, PLEASE DON'T MODIFY BY HAND\n", "\n"])
for document in get_documents():
if 'deprecated' in document:
continue
snippet = to_snippet(document)
if not isinstance(snippet, str):
# python2 compatibility
snippet = snippet.encode('utf-8')
f.write(snippet)
f.write("\n\n")

40
etc/soft/vim/vim/+plugins/ansible-vim/ftdetect/ansible.vim

@ -0,0 +1,40 @@
function! s:isAnsible()
let filepath = expand("%:p")
let filename = expand("%:t")
if filepath =~ '\v/(defaults|tasks|roles|handlers|meta|vars)/.*\.ya?ml$' | return 1 | en
if filepath =~ '\v/(group|host)_vars/' | return 1 | en
if filename =~ '\v(playbook|site|main|local)\.ya?ml$' | return 1 | en
let shebang = getline(1)
if shebang =~# '^#!.*/bin/env\s\+ansible-playbook\>' | return 1 | en
if shebang =~# '^#!.*/bin/ansible-playbook\>' | return 1 | en
return 0
endfunction
function! s:setupTemplate()
if exists("g:ansible_template_syntaxes")
let filepath = expand("%:p")
for syntax_name in items(g:ansible_template_syntaxes)
let s:syntax_string = '\v/'.syntax_name[0]
if filepath =~ s:syntax_string
execute 'set ft='.syntax_name[1].'.jinja2'
return
endif
endfor
endif
set ft=jinja2
endfunction
augroup ansible_vim_ftyaml_ansible
au!
au BufNewFile,BufRead * if s:isAnsible() | set ft=yaml.ansible | en
augroup END
augroup ansible_vim_ftjinja2
au!
au BufNewFile,BufRead *.j2 call s:setupTemplate()
augroup END
augroup ansible_vim_fthosts
au!
au BufNewFile,BufRead inventory* set ft=ansible_hosts
augroup END

6
etc/soft/vim/vim/+plugins/ansible-vim/ftplugin/ansible.vim

@ -0,0 +1,6 @@
" Slow yaml highlighting workaround
if exists('+regexpengine') && ('&regexpengine' == 0)
setlocal regexpengine=1
endif
set isfname+=@-@
set path+=./../templates,./../files,templates,files

9
etc/soft/vim/vim/+plugins/ansible-vim/ftplugin/ansible_hosts.vim

@ -0,0 +1,9 @@
if exists("b:did_ftplugin")
finish
else
let b:did_ftplugin = 1
endif
setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions-=c
let b:undo_ftplugin = "setl comments< commentstring< formatoptions<"

59
etc/soft/vim/vim/+plugins/ansible-vim/indent/ansible.vim

@ -0,0 +1,59 @@
let s:save_cpo = &cpo
set cpo&vim
setlocal indentexpr=GetAnsibleIndent(v:lnum)
setlocal indentkeys=!^F,o,O,0#,0},0],<:>,-,*<Return>
setlocal nosmartindent
setlocal expandtab
setlocal softtabstop=2
setlocal shiftwidth=2
setlocal commentstring=#%s
setlocal formatoptions+=cl
" c -> wrap long comments, including #
" l -> do not wrap long lines
let s:comment = '\v^\s*#' " # comment
let s:array_entry = '\v^\s*-\s' " - foo
let s:named_module_entry = '\v^\s*-\s*(name|hosts|role):\s*\S' " - name: 'do stuff'
let s:dictionary_entry = '\v^\s*[^:-]+:\s*$' " with_items:
let s:key_value = '\v^\s*[^:-]+:\s*\S' " apt: name=package
let s:scalar_value = '\v:\s*[>|\|]\s*$' " shell: >
if exists('*GetAnsibleIndent')
finish
endif
function GetAnsibleIndent(lnum)
if a:lnum == 1 || !prevnonblank(a:lnum-1)
return 0
endif
if exists("g:ansible_unindent_after_newline")
if (a:lnum -1) != prevnonblank(a:lnum - 1)
return 0
endif
endif
let prevlnum = prevnonblank(a:lnum - 1)
let maintain = indent(prevlnum)
let increase = maintain + &sw
let line = getline(prevlnum)
if line =~ s:array_entry
if line =~ s:named_module_entry
return increase
else
return maintain
endif
elseif line =~ s:dictionary_entry
return increase
elseif line =~ s:key_value
if line =~ s:scalar_value
return increase
else
return maintain
endif
else
return maintain
endif
endfunction
let &cpo = s:save_cpo

104
etc/soft/vim/vim/+plugins/ansible-vim/syntax/ansible.vim

@ -0,0 +1,104 @@
" Vim syntax file
" Language: Ansible YAML/Jinja templates
" Maintainer: Dave Honneffer <pearofducks@gmail.com>
" Last Change: 2018.02.08
if !exists("main_syntax")
let main_syntax = 'yaml'
endif
if exists('b:current_syntax')
let s:current_syntax=b:current_syntax
unlet b:current_syntax
endif
syntax include @Jinja syntax/jinja2.vim
if exists('s:current_syntax')
let b:current_syntax=s:current_syntax
endif
" Jinja
" ================================
syn cluster jinjaSLSBlocks add=jinjaTagBlock,jinjaVarBlock,jinjaComment
" https://github.com/mitsuhiko/jinja2/blob/6b7c0c23/ext/Vim/jinja.vim
syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks
syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,yamlComment,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks
syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,@jinjaSLSBlocks
highlight link jinjaVariable Constant
highlight link jinjaVarDelim Delimiter
" YAML
" ================================
if exists("g:ansible_yamlKeyName")
let s:yamlKey = g:ansible_yamlKeyName
else
let s:yamlKey = "yamlBlockMappingKey"
endif
" Reset some YAML to plain styling
" the number 80 in Ansible isn't any more important than the word root
highlight link yamlInteger NONE
highlight link yamlBool NONE
highlight link yamlFlowString NONE
" but it does make sense we visualize quotes easily
highlight link yamlFlowStringDelimiter Delimiter
" This is only found in stephypy/vim-yaml, since it's one line it isn't worth
" making conditional
highlight link yamlConstant NONE
fun! s:attribute_highlight(attributes)
if a:attributes =~ 'a'
syn match ansible_attributes "\v\w+\=" containedin=yamlPlainScalar
else
syn match ansible_attributes "\v^\s*\w+\=" containedin=yamlPlainScalar
endif
if a:attributes =~ 'n'
highlight link ansible_attributes NONE
elseif a:attributes =~ 'd'
highlight link ansible_attributes Comment
else
highlight link ansible_attributes Structure
endif
endfun
if exists("g:ansible_attribute_highlight")
call s:attribute_highlight(g:ansible_attribute_highlight)
else
call s:attribute_highlight('ad')
endif
if exists("g:ansible_name_highlight")
execute 'syn keyword ansible_name name containedin='.s:yamlKey.' contained'
if g:ansible_name_highlight =~ 'd'
highlight link ansible_name Comment
else
highlight link ansible_name Underlined
endif
endif
execute 'syn keyword ansible_debug_keywords debug containedin='.s:yamlKey.' contained'
highlight link ansible_debug_keywords Debug
if exists("g:ansible_extra_keywords_highlight")
execute 'syn keyword ansible_extra_special_keywords register always_run changed_when failed_when no_log args vars delegate_to ignore_errors containedin='.s:yamlKey.' contained'
highlight link ansible_extra_special_keywords Statement
endif
execute 'syn keyword ansible_normal_keywords include include_tasks import_tasks until retries delay when only_if become become_user block rescue always notify containedin='.s:yamlKey.' contained'
if exists("g:ansible_normal_keywords_highlight")
execute 'highlight link ansible_normal_keywords '.g:ansible_normal_keywords_highlight
else
highlight link ansible_normal_keywords Statement
endif
execute 'syn match ansible_with_keywords "\vwith_.+" containedin='.s:yamlKey.' contained'
if exists("g:ansible_with_keywords_highlight")
execute 'highlight link ansible_with_keywords '.g:ansible_with_keywords_highlight
else
highlight link ansible_with_keywords Statement
endif
let b:current_syntax = "ansible"

31
etc/soft/vim/vim/+plugins/ansible-vim/syntax/ansible_hosts.vim

@ -0,0 +1,31 @@
" Vim syntax file
" Language: Ansible hosts files
" Maintainer: Dave Honneffer <pearofducks@gmail.com>
" Last Change: 2015.09.23
if exists("b:current_syntax")
finish
endif
syn case ignore
syn match hostsFirstWord "\v^\S+"
syn match hostsAttributes "\v\S*\="
syn region hostsHeader start="\v^\s*\[" end="\v\]"
syn keyword hostsHeaderSpecials children vars containedin=hostsHeader contained
syn match hostsComment "\v^[#;].*$"
highlight link hostsFirstWord Label
highlight link hostsHeader Define
highlight link hostsComment Comment
highlight link hostsHeaderSpecials Identifier
highlight link hostsAttributes Structure
if exists("g:ansible_attribute_highlight")
if g:ansible_attribute_highlight =~ 'n'
highlight link hostsAttributes NONE
elseif g:ansible_attribute_highlight =~ 'd'
highlight link hostsAttributes Comment
endif
endif
let b:current_syntax = "ansible_hosts"

97
etc/soft/vim/vim/+plugins/ansible-vim/syntax/jinja2.vim

@ -0,0 +1,97 @@
" Vim syntax file
" Language: Jinja2 - with special modifications for compound-filetype
" compatibility
" Maintainer: Dave Honneffer <pearofducks@gmail.com>
" Last Change: 2018.02.11
if !exists("main_syntax")
let main_syntax = 'jinja2'
endif
let b:current_syntax = ''
unlet b:current_syntax
syntax case match
" Jinja template built-in tags and parameters (without filter, macro, is and raw, they
" have special threatment)
syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained and if else in not or recursive as import
syn keyword jinjaStatement containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained is filter skipwhite nextgroup=jinjaFilter
syn keyword jinjaStatement containedin=jinjaTagBlock contained macro skipwhite nextgroup=jinjaFunction
syn keyword jinjaStatement containedin=jinjaTagBlock contained block skipwhite nextgroup=jinjaBlockName
" Variable Names
syn match jinjaVariable containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[a-zA-Z_][a-zA-Z0-9_]*/
syn keyword jinjaSpecial containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained false true none False True None loop super caller varargs kwargs
" Filters
syn match jinjaOperator "|" containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained skipwhite nextgroup=jinjaFilter
syn match jinjaFilter contained /[a-zA-Z_][a-zA-Z0-9_]*/
syn match jinjaFunction contained /[a-zA-Z_][a-zA-Z0-9_]*/
syn match jinjaBlockName contained /[a-zA-Z_][a-zA-Z0-9_]*/
" Jinja template constants
syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/"/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\"/ end=/"/
syn region jinjaString containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained start=/'/ skip=/\(\\\)\@<!\(\(\\\\\)\@>\)*\\'/ end=/'/
syn match jinjaNumber containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[0-9]\+\(\.[0-9]\+\)\?/
" Operators
syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[+\-*\/<>=!,:]/
syn match jinjaPunctuation containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /[()\[\]]/
syn match jinjaOperator containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained /\./ nextgroup=jinjaAttribute
syn match jinjaAttribute contained /[a-zA-Z_][a-zA-Z0-9_]*/
" Jinja template tag and variable blocks
syn region jinjaNested matchgroup=jinjaOperator start="(" end=")" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
syn region jinjaNested matchgroup=jinjaOperator start="\[" end="\]" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
syn region jinjaNested matchgroup=jinjaOperator start="{" end="}" transparent display containedin=jinjaVarBlock,jinjaTagBlock,jinjaNested contained
syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,yamlComment,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment
" Jinja template 'raw' tag
syn region jinjaRaw matchgroup=jinjaRawDelim start="{%\s*raw\s*%}" end="{%\s*endraw\s*%}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,jinjaComment
" Jinja comments
syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString
" Block start keywords. A bit tricker. We only highlight at the start of a
" tag block and only if the name is not followed by a comma or equals sign
" which usually means that we have to deal with an assignment.
syn match jinjaStatement containedin=jinjaTagBlock contained /\({%-\?\s*\)\@<=\<[a-zA-Z_][a-zA-Z0-9_]*\>\(\s*[,=]\)\@!/
" and context modifiers
syn match jinjaStatement containedin=jinjaTagBlock contained /\<with\(out\)\?\s\+context\>/
" Define the default highlighting.
if !exists("did_jinja_syn_inits")
command -nargs=+ HiLink hi def link <args>
HiLink jinjaPunctuation jinjaOperator
HiLink jinjaAttribute jinjaVariable
HiLink jinjaFunction jinjaFilter
HiLink jinjaTagDelim jinjaTagBlock
HiLink jinjaVarDelim jinjaVarBlock
HiLink jinjaCommentDelim jinjaComment
HiLink jinjaRawDelim jinja
HiLink jinjaSpecial Special
HiLink jinjaOperator Normal
HiLink jinjaRaw Normal
HiLink jinjaTagBlock PreProc
HiLink jinjaVarBlock PreProc
HiLink jinjaStatement Statement
HiLink jinjaFilter Function
HiLink jinjaBlockName Function
HiLink jinjaVariable Identifier
HiLink jinjaString Constant
HiLink jinjaNumber Constant
HiLink jinjaComment Comment
delcommand HiLink
endif
let b:current_syntax = "jinja2"

31
etc/soft/vim/vim/+plugins/ansible-vim/syntax/jinja2.vim_LICENSE

@ -0,0 +1,31 @@
Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details.
Some rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading…
Cancel
Save