Search code examples
vimfoldvim-syntax-highlighting

Vim syntax defined folding transparent colour


I wrote Vim syntax highlighting definition code, and also defined folding. Now I can use folding but when I have the folded line, I want to colour differently for the folding function part and the actual code

+--  10 lines: XXXXXX

So I want to keep the XXXXXX part still be coloured as the original syntax colour to stand out from rest of line. How can I define transparency for the folding syntax?


Solution

  • Unfortunately, that currently isn't possible. There are two highlight groups that control the visual representation of folds: Folded (for the entire line) and FoldColumn (for the left-side representation of fold state). Likewise, "transparency" does not apply here; the fold text is a custom[izable] extract of the buffer contents. The real buffer contents are folded away, and not rendered.

    I faintly remember patches that allow different highlight groups for fold levels or nested folds, but none of that has been included in Vim yet.

    What you want to achieve would be very visually appealing. I see the following difficulties in implementing this, though:

    The regular filetype syntax (that you want to apply) would have to match after the +-- 10 lines: prefix. Many syntaxes have elaborate containment or sequencing, and may fail to apply. Others may apply, but (because of folded away stuff), lose their regular context, so following lines will be messed up. This could be fixed with special syntax rules (maybe just including low-level stuff like syntax keywords and simple :syn match), but these would require the collaboration of each syntax, so hundreds of scripts would have to be extended by the various authors.