install.fairie/dotfiles/.vim/plugged/ansible-vim/ftdetect/ansible.vim
Git E2E Dev Test Username 8a6af30c98 git subrepo clone https://github.com/pearofducks/ansible-vim.git ./dotfiles/.vim/plugged/ansible-vim
subrepo:
  subdir:   "dotfiles/.vim/plugged/ansible-vim"
  merged:   "93798e8c8"
upstream:
  origin:   "https://github.com/pearofducks/ansible-vim.git"
  branch:   "master"
  commit:   "93798e8c8"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
2022-10-18 10:37:50 -04:00

45 lines
1.3 KiB
VimL

function! s:isAnsible()
let filepath = expand("%:p")
let filename = expand("%:t")
if filepath =~ '\v/(tasks|roles|handlers)/.*\.ya?ml$' | return 1 | en
if filepath =~ '\v/(group|host)_vars/' | return 1 | en
let s:ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'
if exists("g:ansible_ftdetect_filename_regex")
let s:ftdetect_filename_regex = g:ansible_ftdetect_filename_regex
endif
if filename =~ s:ftdetect_filename_regex | 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 hosts set ft=ansible_hosts
augroup END