Search code examples
vimvim-syntax-highlighting

Vim Conceal not working for double equals


I'm trying to write a custom conceal script to replace == by .

However, my syntax match seems to be working only when I put = and not ==.

content.js

var body = document.body;
if (body == 'body')
    console.log('yes');

javascript.vim

Everything works fine when I do this:

syntax match jsEqual "=" conceal cchar=≈

When I change it to:

syntax match jsEqual "==" conceal cchar=≈

Nothing is concealed.


Solution

  • I can reproduce this with the vim javascript syntax plugin, but not with the built-in syntax script. That extended syntax defines a syntax group javaScriptOpSymbols for ==.

    To find out which syntax group causes the highlighting. :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin.

    To make your conceal group apply, you need to make it applicable inside that syntax group that covers the ==; this is done via the :help :syn-containedin attribute:

    syntax match jsEqual "==" conceal cchar=≈ containedin=javaScriptOpSymbols