1

I've asked this question on StackOverflow and they suggested to ask it here. I am trying to set a custom syntax highlighting for BSD rc.conf file which looks like:

name=YES
anothername=NO
third="options"

I created years agoo a syntax file:

if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

if !exists("main_syntax")
  let main_syntax = 'sh'
endif

if version < 600
  so <sfile>:p:h/sh.vim
else
  runtime! syntax/sh.vim
  unlet b:current_syntax
endif

syntax case match

syn keyword rcconfKeywordYes YES
syn keyword rcconfKeywordNo NO

let b:current_syntax = "rcconf"

hi def link rcconfKeywordYes Type
hi def link rcconfKeywordNo Special

This worked before, but now in vim 8 it works only if there are spaces between keywords and other symbols:

name = YES
anothername = NO
3
  • 1
    So there is no highlighting at all of foo=bar? You say "years ago"...note that pre-vim 6 this was apparently not using the standard sh.vim syntax file so maybe that's the difference.
    – B Layer
    Aug 26, 2020 at 13:14
  • 1
    Welcome to Vi and Vim!
    – D. Ben Knoble
    Aug 26, 2020 at 13:24
  • 1
    Have you tried using dosini filetype? Aug 26, 2020 at 14:31

1 Answer 1

1

It could depend on iskeyword value.
keyword only matches for a complete word, for example, if you define the keyword NO, it will not match NOT or PIANO.
If Vim considers = is a letter, then anothername=NO is a single word, and it's not NO.

You can check if Vim considers = to be a letter with :set iskeyword?.
You can probably fix it: with the command :set iskeyword-==, YES and NO will get colors.
With :set iskeyword+==, they lose they colors again.

You can also use the syntax iskeyword instead (it's not the same, for example it doesn't change abbrev behavior, and it is recommended to use this one).
It's explain at :help syntax|3546.
Try with: :syntax iskeyword @,48-57,192-255,$,_.

I don't know which one breaks your syntax, so you can try both.

5
  • 1
    Looks like you might be new here, but great couple of first answers! Welcome!
    – D. Ben Knoble
    Aug 27, 2020 at 13:23
  • 2
    Thanks ! I already used stackexchange websites as "read only user" for at least several months, but only started giving answers since yesterday. Aug 27, 2020 at 13:30
  • Thank you for answer. Unfotunatly it does not help. At the beginning iskeyword=@,48-57,_,192-255, after set iskeyword-== the same and no color, after set iskeyword+== the equal sign has been added iskeyword=@,48-57,_,192-255,= and no colors appeared also
    – dstep
    Sep 7, 2020 at 16:28
  • what is the output of the command :syntax iskeyword ? Sep 8, 2020 at 15:55
  • syntax iskeyword @,48-57,_,192-255,-
    – dstep
    Sep 14, 2020 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.