2

tl;dr

Are there any undesirable side-effects connected to the use of :highlight! default link {from-group} {to-group} as compared to :highlight default … that I should be aware of when editing/creating a syntax file?

Director's cut

In the context of trying to understand how syntax highlighting works in Vim, I tend to have opened the syntax file for a given language and a sample of code written in that language, so that I can see the effects on the latter of editing the former simply by sourcing my .vimrc.

However, I have seen that some type of edit is not reflected unless I open the file in another session of Vim.

For example, I changed this line in sed.vim

hi def link sedError       Error

to this

hi def link sedError       NONE

and then sourced my .vimrc in a flawed file.sed I had open beside; I saw the Error highlight disappear. This is what I expected. Then I restored the line above as it was, sourced my .vimrc again, but the color did not come back.

Based on what I read in :h :hi-link, it seems I could simply add ! to the hilight command; I have tried, and it works.

However, I have observed that only fortran.vim and chicken.vim make links like this

hi! def link fortranTypeR       fortranType

whereas all other syntax files use something like this (from cpp.vim)

hi def link cppBoolean      Boolean

therefore I started suspecting that there could be something not advisable in using hi! instead of hi in this situation.

1 Answer 1

1

I suspect the reason not all syntax scripts use ! when linking highlight definitions is that users could have a preferred way to show certain things in certain ways, and declare these on their .vimrc. Syntax scripts are loaded when a FileType event occurs, i.e. after the .vimrc file is sourced, so if the syntax script uses hi! link it doesn't matter that the user had something like hi! def link cppBoolean Function, the former will overwrite the latter.

I often switch colour schemes, and I have seen weird results because of the lack of ! in links (and also lack of gui and cterm defaults), so I think the lack of ! should be considered carefully when defining a highlight. If users really want to overwrite some link, they can define them (with !) in scripts in their after directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.