highlighting prefixed keywords

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

highlighting prefixed keywords

Jorge Almeida-2
I need to apply custom highligthing in a setup that should be simple
for people who understand highligthing:

I have a bunch of keywords with a common prefix, the single character
'c'. The keywords are to be listed one by one, not obtained via some
algorithm. Example:

cmount
cumount
copen
cclose
(etc)

So, I want to highlight these keywords, *minus the prefix*,  with some
colour (say, the same colour for all keywords). That is, in "cmount",
only "mount" should be coloured, not the leading 'c'.

TIA

Jorge Almeida

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: highlighting prefixed keywords

Tim Chase
On 2017-12-17 18:49, Jorge Almeida wrote:

> I need to apply custom highligthing in a setup that should be simple
> for people who understand highligthing:
>
> I have a bunch of keywords with a common prefix, the single
> character 'c'. The keywords are to be listed one by one, not
> obtained via some algorithm. Example:
>
> cmount
> cumount
> copen
> cclose
> (etc)
>
> So, I want to highlight these keywords, *minus the prefix*,  with
> some colour (say, the same colour for all keywords). That is, in
> "cmount", only "mount" should be coloured, not the leading 'c'.

Does

  :match Error /\%(\<c\)\@<=\w\+/

give you what you're looking for? Alternatively, if they're a fixed
list of keywords, you can join them together something like

 :match Error /\%(\<c\)\@<=\(mount\|umount\|open\|close\)/

You can adjust the color group to something other than Error, as
that's just what I chose by default.

-tim


--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: highlighting prefixed keywords

Jorge Almeida-2
On Sun, Dec 17, 2017 at 7:02 PM, Tim Chase <[hidden email]> wrote:

> On 2017-12-17 18:49, Jorge Almeida wrote:
>> I need to apply custom highligthing in a setup that should be simple
>> for people who understand highligthing:
>>
>> I have a bunch of keywords with a common prefix, the single
>> character 'c'. The keywords are to be listed one by one, not
>> obtained via some algorithm. Example:
>>
>> cmount
>> cumount
>> copen
>> cclose
>> (etc)
>>
>> So, I want to highlight these keywords, *minus the prefix*,  with
>> some colour (say, the same colour for all keywords). That is, in
>> "cmount", only "mount" should be coloured, not the leading 'c'.
>
> Does
>
>   :match Error /\%(\<c\)\@<=\w\+/
>
> give you what you're looking for? Alternatively, if they're a fixed
> list of keywords, you can join them together something like
>
>  :match Error /\%(\<c\)\@<=\(mount\|umount\|open\|close\)/
>
Indeed it does! (Well, the latter suggestion does.)

I did this:

highlight macro_skin guibg=bg guifg=DarkGreen gui=bold ctermfg=022 cterm=bold
match macro_skin /\%(\<c\)\@<=\(mount\|umount\|open\|close\)/

And that's it. (And just a few minutes after posting, to boot!)

Just a detail: is it possible to enumerate the keywords in a separate
declaration, to improve maintainability? (The actual list  is more
extense). I'm thinking of something similar to:

syntax keyword Foo open  close mount umount

Even if it's not possible, this is good enough.

Thanks

Jorge

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: highlighting prefixed keywords

Tim Chase
On 2017-12-17 19:16, Jorge Almeida wrote:
> Just a detail: is it possible to enumerate the keywords in a
> separate declaration, to improve maintainability? (The actual list
> is more extense). I'm thinking of something similar to:
>
> syntax keyword Foo open  close mount umount
>
> Even if it's not possible, this is good enough.

Also, one might use

 syn match jaKeyword /\<c\%(umount\|mount\|open\|close\)/hs=s+1
 hi def link jaKeyword Identifier

which simplifies the syntax a bit.

Despite multiple attempts, I was unable to get it to work with
syn-keyword as it seems to want a Word boundary between the /\<c/ and
the keyword.  I tried

syn region jaKeywordRegion start='\<c'rs=s+1 end='\>' contains=jaKeyword transparent
"syn keyword jaKeyword contained umount mount open close
syn match jaKeyword contained /umount\|mount\|open\|close/
hi def link jaKeyword Identifier

and it worked fine with the "match" version but failed with the
"keyword" version.  I also tried various configurations of ms= and
rs= offsets to no avail.

-tim



--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: highlighting prefixed keywords

Jorge Almeida-2
On Sun, Dec 17, 2017 at 9:14 PM, Tim Chase <[hidden email]> wrote:
> On 2017-12-17 19:16, Jorge Almeida wrote:
>> Just a detail: is it possible to enumerate the keywords in a
>> separate declaration, to improve maintainability? (The actual list
>> is more extense). I'm thinking of something similar to:
>>
>> syntax keyword Foo open  close mount umount
>>

>  syn match jaKeyword /\<c\%(umount\|mount\|open\|close\)/hs=s+1
>  hi def link jaKeyword Identifier
>
> which simplifies the syntax a bit.
>
OK, thanks. As it stands now it does the job.

Syntax highlighting is a great feature. Pity that it's so difficult to learn.

Cheers

Jorge

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.