Sunday, May 1, 2011

Re: Highlight group exists but no highlighting

> syntax keyword UserKeywords Samkit CHECKME REVIEW CHECKME
> containedin=ALL
> highlight def link UserKeywords Todo

You probably don't want the 'def' in there, but it probably doesn't
really matter.

> This works fine if I open an unnamed file like just "gvim".

Syntax is buffer-specific, so as soon as you edit any other file of any
other type, it will no longer be in effect.

> I am suspecting that something is calling "highlight clear" but I am
> not sure of this.

That won't be happening. You can confirm this, though, by typing

:verbose highlight

It will show the highlight group (even with 'cleared' beside it, if it
has been cleared), and in the line below, the file that last set it (or
cleared it).

Likewise

:verbose syntax

will let you know where syntax groups originated, though this is often a
little less useful (cleared groups are not shown, I don't think).

> Additionally after opening 1.c I checked if my syntax group exists and
> it exists so it can only be the work of "highlight clear".

This can't really be possible (that the syntax group exists). Probably
the highlight group for your syntax item exists, but the actual syntax
rule will not. I.e. you will see it listed in :highlight but not in
:syntax.

> :hi UserKeywords
> UserKeywords xxx links to Todo

This is as expected.

If you do :syn UserKeywords, though, you will not see it.

> For this much highlighting I would not like to create a new
> runtimepath/after/syntax/default.vim containing above syntax+highlight
> group commands and then source it for every BufRead and FileRead.

You can use an autocommand to just run the syntax you want on those
events. Put something like this in .vimrc:

autocmd BufNewFile,BufRead * syntax keyword UserKeywords
\ Samkit CHECKME REVIEW CHECKME containedin=ALL

Adjust the * if you want to apply to specific filetypes, and ensure it
is after the filetype on and/or syntax on commands in your vimrc or the
autocommanes may run before those related to syntax and thus the former
may have the syntax cleared by the latter.

You probably don't need to do the highlight command similarly; just
having it in your .vimrc as you currently do is probably enough. But if
you need to include it, or a little more highlighting, in an
autocommand, a small function in your .vimrc which you call with an
autocommand becomes an attractive option.

Hope this helps, and gives enough debugging tips, too.

Cheers,

Ben.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment