2
1
I have tried to extend the C syntax in Vim with the example in the manual.
First I launch vim without any config:
vim -u NONE test.c
Then I load the c-syntax and create my extension
syntax on
syntax keyword myword HELP containedin=cComment contained
highlight myword guibg=red
code:
1: /* HELP */
2: int main(int argc, char **argv) {
3: int HELP = 0;
4: if(HELP);
5: }
HELP is highlighted on line 1 as expected. It is also highlighted on line 4, is there some explanation for this?
If I
:call SyntaxAttr()
when the cursor is within the parentheses, it only gives megroup: myword guibg=red(#ff0000)
. I do not get why I should includecBlock
, since I want to restrict the number of places where the myword highlighting is used. – Klas. S – 2017-11-02T23:15:14.037The
cBlock
encompasses everything within{
...}
and prevents the match. This definition is found in$VIMRUNTIME/syntax/c.vim
. It would obscure theHELP
in line 4, too; however, that is contained incParen
whichcontains=ALLBUT,...
TheALL
makes this include yourmyword
, and so it is highlighted without you having tocontainedin=cParen
. – Ingo Karkat – 2017-11-03T08:08:45.153