pearofducks / ansible-vim

A vim plugin for syntax highlighting Ansible's common filetypes
MIT License
796 stars 98 forks source link

Possible to use backrefs in ansible_template_syntaxes? #88

Closed stove-panini closed 4 years ago

stove-panini commented 4 years ago

The jinja2 syntax highlighting doesn't automatically pick up on the root filetype. I tried to use backrefs to help with this, but it doesn't seem to work.

let g:ansible_template_syntaxes = { '\(.*\)\.\(.*\)\.j2': '\2' }

I know with vim, you need to escape the parentheses for capturing groups, but I tried 'em unescaped, too. Here's the breakdown:

\(.*\) - Capture Group 1, the filename \. - A literal dot \(.*\) - Capture Group 2, the root filetype \.j2 - The j2 filetype

The value of the setting should be \2, whatever was in Capture Group 2.

pearofducks commented 4 years ago

The loop for this is pretty naive, meant mostly for basic patterns and quick setups.

It's probably best to just have a workaround for this in your vimrc - and set the filetype manually.