如何突出显示" - >"我的coffee.vim语法文件中的符号?

时间:2014-03-13 16:22:34

标签: javascript vim coffeescript

我刚刚将javascript.vim复制到coffee.vim,现在咖啡文件突出显示为js文件。现在我想制作CoffeScript功能箭头“ - >”颜色与:

相同
hi Special         guifg=#66D9EF guibg=bg      gui=italic

我不确定从哪里开始。

有什么建议吗?

语法/ coffee.vim:

" Language:    CoffeeScript
" Maintainer:  Mick Koch <kchmck@gmail.com>
" URL:         http://github.com/kchmck/vim-coffee-script
" License:     WTFPL

if !exists("main_syntax")
  if version < 600
    syntax clear
  elseif exists("b:current_syntax")
    finish
  endif
  let main_syntax = 'coffeescript'
endif

"" Drop fold if it is set but VIM doesn't support it.
let b:coffeescript_fold='true'
if version < 600    " Don't support the old version
  unlet! b:coffeescript_fold
endif

"" dollar sign is permittd anywhere in an identifier
setlocal iskeyword+=$

syntax sync fromstart

"" coffeescript comments
syntax keyword coffeescriptCommentTodo    TODO FIXME XXX TBD contained
syntax region  coffeescriptLineComment    start=+\/\/+ end=+$+ keepend contains=coffeescriptCommentTodo,@Spell
syntax region  coffeescriptEnvComment     start="\%^#!" end="$" display
syntax region  coffeescriptLineComment    start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=coffeescriptCommentTodo,@Spell fold
syntax region  coffeescriptCvsTag         start="\$\cid:" end="\$" oneline contained
syntax region  coffeescriptComment        start="/\*"  end="\*/" contains=coffeescriptCommentTodo,coffeescriptCvsTag,@Spell fold

"" JSDoc / JSDoc Toolkit
if !exists("coffeescript_ignore_coffeescriptdoc")
  syntax case ignore

  "" syntax coloring for javadoc comments (HTML)
  "syntax include @javaHtml <sfile>:p:h/html.vim
  "unlet b:current_syntax

  syntax region coffeescriptDocComment      matchgroup=coffeescriptComment start="/\*\*\s*"  end="\*/" contains=coffeescriptDocTags,coffeescriptCommentTodo,coffeescriptCvsTag,@coffeescriptHtml,@Spell fold

  " tags containing a param
  syntax match  coffeescriptDocTags         contained "@\(augments\|base\|borrows\|class\|constructs\|default\|exception\|exports\|extends\|file\|member\|memberOf\|methodOf\|module\|name\|namespace\|optional\|requires\|title\|throws\|version\)\>" nextgroup=coffeescriptDocParam skipwhite
  " tags containing type and param
  syntax match  coffeescriptDocTags         contained "@\(argument\|param\|property\)\>" nextgroup=coffeescriptDocType skipwhite
  " tags containing type but no param
  syntax match  coffeescriptDocTags         contained "@\(type\|return\|returns\|api\)\>" nextgroup=coffeescriptDocTypeNoParam skipwhite
  " tags containing references
  syntax match  coffeescriptDocTags         contained "@\(lends\|link\|see\)\>" nextgroup=coffeescriptDocSeeTag skipwhite
  " other tags (no extra syntax)
  syntax match  coffeescriptDocTags         contained "@\(access\|addon\|alias\|author\|beta\|constant\|const\|constructor\|copyright\|deprecated\|description\|event\|example\|exec\|field\|fileOverview\|fileoverview\|function\|global\|ignore\|inner\|license\|overview\|private\|protected\|project\|public\|readonly\|since\|static\)\>"

  syntax region coffeescriptDocType         start="{" end="}" oneline contained nextgroup=coffeescriptDocParam skipwhite
  syntax match  coffeescriptDocType         contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" nextgroup=coffeescriptDocParam skipwhite
  syntax region coffeescriptDocTypeNoParam  start="{" end="}" oneline contained
  syntax match  coffeescriptDocTypeNoParam  contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+"
  syntax match  coffeescriptDocParam        contained "\%(#\|\"\|{\|}\|\w\|\.\|:\|\/\)\+"
  syntax region coffeescriptDocSeeTag       contained matchgroup=coffeescriptDocSeeTag start="{" end="}" contains=coffeescriptDocTags

  syntax case match
endif   "" JSDoc end

syntax case match

"" Syntax in the coffeescript code
syntax match   coffeescriptSpecial        "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
syntax region  coffeescriptStringD        start=+"+  skip=+\\\\\|\\$"+  end=+"+  contains=coffeescriptSpecial,@htmlPreproc
syntax region  coffeescriptStringS        start=+'+  skip=+\\\\\|\\$'+  end=+'+  contains=coffeescriptSpecial,@htmlPreproc
syntax region  coffeescriptRegexpCharClass start=+\[+ end=+\]+ contained
syntax region  coffeescriptRegexpString   start=+\(\(\(return\|case\)\s\+\)\@<=\|\(\([)\]"']\|\d\|\w\)\s*\)\@<!\)/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gimy]\{,4}+ contains=coffeescriptSpecial,coffeescriptRegexpCharClass,@htmlPreproc oneline
syntax match   coffeescriptNumber         /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
syntax match   coffeescriptFloat          /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
syntax match   coffeescriptLabel          /\<\w\+\(\s*:\)\@=/

"" coffeescript Prototype
syntax keyword coffeescriptPrototype      prototype

"" Program Keywords
syntax keyword coffeescriptSource         import export
syntax keyword coffeescriptType           const undefined var void yield 
syntax keyword coffeescriptOperator       delete new in instanceof let typeof
syntax keyword coffeescriptBoolean        true false
syntax keyword coffeescriptNull           null
syntax keyword coffeescriptThis           this

"" Statement Keywords
syntax keyword coffeescriptConditional    if else
syntax keyword coffeescriptRepeat         do while for
syntax keyword coffeescriptBranch         break continue switch case default return
syntax keyword coffeescriptStatement      try catch throw with finally

syntax keyword coffeescriptGlobalObjects  Array Boolean Date Function Infinity JavaArray JavaClass JavaObject JavaPackage Math Number NaN Object Packages RegExp String Undefined java netscape sun

syntax keyword coffeescriptExceptions     Error EvalError RangeError ReferenceError SyntaxError TypeError URIError

syntax keyword coffeescriptFutureKeys     abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public

"" DOM/HTML/CSS specified things

  " DOM2 Objects
  syntax keyword coffeescriptGlobalObjects  DOMImplementation DocumentFragment Document Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction
  syntax keyword coffeescriptExceptions     DOMException

  " DOM2 CONSTANT
  syntax keyword coffeescriptDomErrNo       INDEX_SIZE_ERR DOMSTRING_SIZE_ERR HIERARCHY_REQUEST_ERR WRONG_DOCUMENT_ERR INVALID_CHARACTER_ERR NO_DATA_ALLOWED_ERR NO_MODIFICATION_ALLOWED_ERR NOT_FOUND_ERR NOT_SUPPORTED_ERR INUSE_ATTRIBUTE_ERR INVALID_STATE_ERR SYNTAX_ERR INVALID_MODIFICATION_ERR NAMESPACE_ERR INVALID_ACCESS_ERR
  syntax keyword coffeescriptDomNodeConsts  ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE

  " HTML events and internal variables
  syntax case ignore
  syntax keyword coffeescriptHtmlEvents     onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize
  syntax case match

" Follow stuff should be highligh within a special context
" While it can't be handled with context depended with Regex based highlight
" So, turn it off by default
if exists("coffeescript_enable_domhtmlcss")

    " DOM2 things
    syntax match coffeescriptDomElemAttrs     contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
    syntax match coffeescriptDomElemFuncs     contained /\%(insertBefore\|replaceChild\|removeChild\|appendChild\|hasChildNodes\|cloneNode\|normalize\|isSupported\|hasAttributes\|getAttribute\|setAttribute\|removeAttribute\|getAttributeNode\|setAttributeNode\|removeAttributeNode\|getElementsByTagName\|getAttributeNS\|setAttributeNS\|removeAttributeNS\|getAttributeNodeNS\|setAttributeNodeNS\|getElementsByTagNameNS\|hasAttribute\|hasAttributeNS\)\>/ nextgroup=coffeescriptParen skipwhite
    " HTML things
    syntax match coffeescriptHtmlElemAttrs    contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/
    syntax match coffeescriptHtmlElemFuncs    contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=coffeescriptParen skipwhite

    " CSS Styles in coffeescript
    syntax keyword coffeescriptCssStyles      contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
    syntax keyword coffeescriptCssStyles      contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
    syntax keyword coffeescriptCssStyles      contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
    syntax keyword coffeescriptCssStyles      contained bottom height left position right top width zIndex
    syntax keyword coffeescriptCssStyles      contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout
    syntax keyword coffeescriptCssStyles      contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
    syntax keyword coffeescriptCssStyles      contained listStyle listStyleImage listStylePosition listStyleType
    syntax keyword coffeescriptCssStyles      contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
    syntax keyword coffeescriptCssStyles      contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
    syntax keyword coffeescriptCssStyles      contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
    syntax keyword coffeescriptCssStyles      contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor

    " Highlight ways
    syntax match coffeescriptDotNotation      "\." nextgroup=coffeescriptPrototype,coffeescriptDomElemAttrs,coffeescriptDomElemFuncs,coffeescriptHtmlElemAttrs,coffeescriptHtmlElemFuncs
    syntax match coffeescriptDotNotation      "\.style\." nextgroup=coffeescriptCssStyles

endif "DOM/HTML/CSS

"" end DOM/HTML/CSS specified things


"" Code blocks
" there is a name collision with coffeescriptExpression in html.vim, hence the use of the '2' here
syntax cluster coffeescriptExpression2 contains=coffeescriptComment,coffeescriptLineComment,coffeescriptDocComment,coffeescriptStringD,coffeescriptStringS,coffeescriptRegexpString,coffeescriptNumber,coffeescriptFloat,coffeescriptSource,coffeescriptThis,coffeescriptType,coffeescriptOperator,coffeescriptBoolean,coffeescriptNull,coffeescriptFunction,coffeescriptGlobalObjects,coffeescriptExceptions,coffeescriptFutureKeys,coffeescriptDomErrNo,coffeescriptDomNodeConsts,coffeescriptHtmlEvents,coffeescriptDotNotation,coffeescriptBracket,coffeescriptParen,coffeescriptBlock,coffeescriptParenError
syntax cluster coffeescriptAll       contains=@coffeescriptExpression2,coffeescriptLabel,coffeescriptConditional,coffeescriptRepeat,coffeescriptBranch,coffeescriptStatement,coffeescriptTernaryIf
syntax region  coffeescriptBracket   matchgroup=coffeescriptBracket transparent start="\[" end="\]" contains=@coffeescriptAll,coffeescriptParensErrB,coffeescriptParensErrC,coffeescriptBracket,coffeescriptParen,coffeescriptBlock,@htmlPreproc
syntax region  coffeescriptParen     matchgroup=coffeescriptParen   transparent start="("  end=")"  contains=@coffeescriptAll,coffeescriptParensErrA,coffeescriptParensErrC,coffeescriptParen,coffeescriptBracket,coffeescriptBlock,@htmlPreproc
syntax region  coffeescriptBlock     matchgroup=coffeescriptBlock   transparent start="{"  end="}"  contains=@coffeescriptAll,coffeescriptParensErrA,coffeescriptParensErrB,coffeescriptParen,coffeescriptBracket,coffeescriptBlock,@htmlPreproc 
syntax region  coffeescriptTernaryIf matchgroup=coffeescriptTernaryIfOperator start=+?+  end=+:+  contains=@coffeescriptExpression2

"" catch errors caused by wrong parenthesis
syntax match   coffeescriptParensError    ")\|}\|\]"
syntax match   coffeescriptParensErrA     contained "\]"
syntax match   coffeescriptParensErrB     contained ")"
syntax match   coffeescriptParensErrC     contained "}"

if main_syntax == "coffeescript"
  syntax sync clear
  syntax sync ccomment coffeescriptComment minlines=200
  syntax sync match coffeescriptHighlight grouphere coffeescriptBlock /{/
endif

"" Fold control
if exists("b:coffeescript_fold")
    syntax match   coffeescriptFunction       /\<function\>/ nextgroup=coffeescriptFuncName skipwhite
    syntax match   coffeescriptOpAssign       /=\@<!=/ nextgroup=coffeescriptFuncBlock skipwhite skipempty
    syntax region  coffeescriptFuncName       contained matchgroup=coffeescriptFuncName start=/\%(\$\|\w\)*\s*(/ end=/)/ contains=coffeescriptLineComment,coffeescriptComment nextgroup=coffeescriptFuncBlock skipwhite skipempty
    syntax region  coffeescriptFuncBlock      contained matchgroup=coffeescriptFuncBlock start="{" end="}" contains=@coffeescriptAll,coffeescriptParensErrA,coffeescriptParensErrB,coffeescriptParen,coffeescriptBracket,coffeescriptBlock fold
else
    syntax keyword coffeescriptFunction       function
endif

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_coffeescript_syn_inits")
  if version < 508
    let did_coffeescript_syn_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif
  HiLink coffeescriptComment              Comment
  HiLink coffeescriptLineComment          Comment
  HiLink coffeescriptEnvComment           PreProc
  HiLink coffeescriptDocComment           Comment
  HiLink coffeescriptCommentTodo          Todo
  HiLink coffeescriptCvsTag               Function
  HiLink coffeescriptDocTags              Special
  HiLink coffeescriptDocSeeTag            Function
  HiLink coffeescriptDocType              Type
  HiLink coffeescriptDocTypeNoParam       Type
  HiLink coffeescriptDocParam             Label
  HiLink coffeescriptStringS              String
  HiLink coffeescriptStringD              String
  HiLink coffeescriptTernaryIfOperator    Conditional
  HiLink coffeescriptRegexpString         String
  HiLink coffeescriptRegexpCharClass      Character
  HiLink coffeescriptCharacter            Character
  HiLink coffeescriptPrototype            Type
  HiLink coffeescriptConditional          Conditional
  HiLink coffeescriptBranch               Conditional
  HiLink coffeescriptRepeat               Repeat
  HiLink coffeescriptStatement            Statement
  HiLink coffeescriptFunction             Function
  HiLink coffeescriptError                Error
  HiLink coffeescriptParensError          Error
  HiLink coffeescriptParensErrA           Error
  HiLink coffeescriptParensErrB           Error
  HiLink coffeescriptParensErrC           Error
  HiLink coffeescriptOperator             Operator
  HiLink coffeescriptType                 Type
  HiLink coffeescriptThis                 Type
  HiLink coffeescriptNull                 Type
  HiLink coffeescriptNumber               Number
  HiLink coffeescriptFloat                Number
  HiLink coffeescriptBoolean              Boolean
  HiLink coffeescriptLabel                Label
  HiLink coffeescriptSpecial              Special
  HiLink coffeescriptSource               Special
  HiLink coffeescriptGlobalObjects        Special
  HiLink coffeescriptExceptions           Special

  HiLink coffeescriptDomErrNo             Constant
  HiLink coffeescriptDomNodeConsts        Constant
  HiLink coffeescriptDomElemAttrs         Label
  HiLink coffeescriptDomElemFuncs         PreProc

  HiLink coffeescriptHtmlEvents           Special
  HiLink coffeescriptHtmlElemAttrs        Label
  HiLink coffeescriptHtmlElemFuncs        PreProc

  HiLink coffeescriptCssStyles            Label

  delcommand HiLink
endif

" Define the htmlcoffeescript for HTML syntax html.vim
"syntax clear htmlcoffeescript
"syntax clear coffeescriptExpression
syntax cluster  htmlcoffeescript contains=@coffeescriptAll,coffeescriptBracket,coffeescriptParen,coffeescriptBlock,coffeescriptParenError
syntax cluster  coffeescriptExpression contains=@coffeescriptAll,coffeescriptBracket,coffeescriptParen,coffeescriptBlock,coffeescriptParenError,@htmlPreproc
" Vim's default html.vim highlights all coffeescript as 'Special'
hi! def link coffeescript NONE

let b:current_syntax = "coffeescript"
if main_syntax == 'coffeescript'
  unlet main_syntax
endif

" vim: ts=4

编辑:

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:2)

如果到目前为止->与任何其他语法组不匹配,那么它应该像

一样简单
:syntax match coffeescriptArrow "->"
:highlight def link coffeescriptArrow Special

如果您不想修改原始语法文件,请将其放入~/.vim/after/syntax/coffeescript.vim