vim-ansible-yaml
vim-ansible-yaml copied to clipboard
Add Jinja highlighting for special Ansible functions
Strings, encased or otherwise, should be highlighted as if they were between Jinja variable blocks for the following keys:
- when
- changed_when
- with_*
There are probably more, but they can be added later.
In this example
- name: silly rule
command: echo "when {{ when }}"
when: some_condition
are you saying that you want the second and third "when" to be in the same highlight group? I assume you do not want anything special for the first "when".
Currently, the three "when"s are
- yamlString
- jinjaVariable
- ansibleConditional
You are correct, I want the second and third "when" to be highlighted the same.
Essentially all that is required is making it so that the value for the mapping for ansibleRepeat and ansibleConditional is set to be the same as jinjaVarBlock but without the region requirements of {{ and ``}}`.
I am still not sure what you want. If you want the third "when" in the example to be highlighted the same way that the second is now, then all it takes is
:hi link ansibleConditional Normal " or jinjaVariable
and I guess you would do the same for ansibleRepeat.
It looks as though jinjaVariable is explicitly highlighted as Normal, and there is no highlight group defined for jinjaVarBlock.
That's not quite the case. Notice that ansibleRepeat and ansibleConditional are both essentially just keywords.
I do not want to change ansibleRepeat and ansibleConditional, which are syntax items which are contained within yamlKey.
What I want is the value, not the key in the mapping of yamlMapping to be the same as the syntax group of jinjaVarBlock. This value is what is after the character :, which is after ansibleRepeat and ansibleConditional.
jinjaVarBlock contains:
jinjaStatementjinjaVariablejinjaSpecialjinjaOperatorjinjaStringjinjaNumberjinjaNested
So making the value use jinjaVariable would not match everything necessary.
For Ansible when, changed_when and with_* statements, the value of the YAML mapping is interpreted exactly the same as a Jinja2 block that goes between {{ .. }}.
I was right about one thing:
I am still not sure what you want.
Please keep the terminology straight: syntax groups and highlight groups are closely related, but they are not the same. :help group-name.
I do not want to change
ansibleRepeatandansibleConditional, which are highlighted asyamlKey
No, this is how they are highlighted:
HiLink ansibleConditional Statement
HiLink ansibleRepeat Repeat
(BTW, is there an easy way to generate those links, or do you type in things like #L24-L25 yourself?)
I am pretty sure that my previous comment is completely correct as stated. What may be wrong is the hypothesis:
If you want the third "when" in the example to be highlighted the same way that the second is now ...
If that is the problem, then please be clear about which word you want highlighted differently. Or supply your own example. Here is a screenshot of the example I proposed:

Sorry, I did interchange terminology incorrectly. I edited my previous comment in hopes that it is more clear.
Regarding those links with the lines highlighted, when viewing a code file you can click a line number to highlight it. This changes the URL of the current page to correspond to the change. To select a line range, click the first line you want then shift-click the last line you want.
Essentially it is not a single word's highlighting to be changed, otherwise I would have implemented this a long time ago. I want the value of the key-value mapping to be highlighted as I described above.
Thanks for the tip on using GitHub.
Referring to the example, I now think that you want to leave the "when"'s as they are, but change "some_condition" to have the same highlighting as the second "when". In other words, "some_condition" should be part of the jinjaVarBlock syntax group ... or part of a syntax group that behaves just like the jinjaVarBlock syntax group.
Sounds like I finally got my thoughts across properly, haha. Sorry about all the communication issues.
Yes, "some_condition" should be part of a syntax group that behaves just like jinjaVarBlock.