pearofducks / ansible-vim

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

Strings no longer getting the "String" highlight group, but getting the "Normal" highlight group #119

Closed life5ign closed 3 years ago

life5ign commented 3 years ago

For example, "this string" gets assigned the Normal highlight group, after installing this plugin. I would just override this, but my knowledge of how vim identifies what patterns get assigned to what highlight group is lacking. Can this be fixed, is this just me, and is there a .vimrc override as a quick fix?

pearofducks commented 3 years ago

What highlight is used is dependent on where in YAML context the content occurs. This doesn't sound like a bug, but if you provide a bit more context I can look into it.

You can also check what YAML does, IIRC it doesn't highlight "-enclosed strings either.

life5ign commented 3 years ago

Thanks, here is an example:

- name: Get information about main vst production security group and write results to a local file
  hosts: localhost
  gather_facts: False
  vars:
    boto_profile: "{{ vst_gov_boto_profile }}"
    security_group_id: "blah"
...

"blah" looks the same as the content after name: Get.... which I realize, is how it looks in the markup here; but for me, yaml did highlight strings with the String syntax group highlight color, so that it would be different from characters not enclosed in quotes (like the Get... above) which I kind of miss...it was a nice red color for me. What other info can I provide?

pearofducks commented 3 years ago

You can set strings back to whatever highlight you'd like by setting:

highlight link yamlFlowString VALUE HERE

in your vimrc. You should be able to use augroup as mentioned in the README to target this specific plugin/filetype detection.

life5ign commented 3 years ago

Awesome, thank you. This worked for me:

" set strings back to getting the String highlight group for yaml.ansible
" filetypes
highlight link yamlFlowString String
life5ign commented 3 years ago

Actually, this led to a situation where the desired highlighting would work when .vimrc was sourced, but would revert to non String highlighted strings when the file was reloaded with :e (i.e. the buffer was re-read), so I needed to do this (notice I want this syntax for any .yml, and this could be adjusted with the pattern)

" detect yaml.ansible filetye for all yaml files and
" set strings back to getting the String highlight group for yaml.ansible
" filetypes
au BufRead,BufNewFile *.yml set filetype=yaml.ansible | highlight link yamlFlowString String