vim 中的语法高亮

vim 中的语法高亮

我有扩展名为*.sc.因此,为了对我创建的该类型文本文件中的某些关键字进行语法突出显示~/.vim/syntax/sc.cim。以下是文件内容。

user $ cd ~/.vim/syntax/
user $ cat sc.vim 
" Syntax highlightor file for files ending in *.sc
syn keyword basicLanguageKeywords interface channel behavior
user $

我还添加了以下行~/.vimrc

au BufRead,BufNewFile *.sc set filetype=sc

现在我希望当我:set syntax=sc在 vim 中执行此操作时,语法突出显示将对*.sc文件有效。但它不起作用。

这里出了什么问题?

答案1

如果您创建自己的语法组名称,例如basicLanguageKeywords,那么您必须为它们创建突出显示设置。坚持使用常用的名称,以便您的语法设置适用于大多数配色方案。查看:h group-name:

To be able to allow each user to pick his favorite set of colors, there must
be preferred names for highlight groups that are common for many languages.
These are the suggested group names (if syntax highlighting works properly
you can see the actual color, except for "Ignore"):
    *Comment        any comment

    *Constant       any constant
     String         a string constant: "this is a string"
     Character      a character constant: 'c', '\n'
     Number         a number constant: 234, 0xff
     Boolean        a boolean constant: TRUE, false
     Float          a floating point constant: 2.3e10

    *Identifier     any variable name
     Function       function name (also: methods for classes)

    *Statement      any statement
     Conditional    if, then, else, endif, switch, etc.
     Repeat         for, do, while, etc.
     Label          case, default, etc.
     Operator       "sizeof", "+", "*", etc.
     Keyword        any other keyword
     Exception      try, catch, throw

在这种情况下,那就是Keyword

相关内容