1" Vim syntax file 2" Language: JavaScript 3" Maintainer: Claudio Fleiner <[email protected]> 4" Updaters: Scott Shattuck (ss) <[email protected]> 5" URL: http://www.fleiner.com/vim/syntax/javascript.vim 6" Changes: (ss) added keywords, reserved words, and other identifiers 7" (ss) repaired several quoting and grouping glitches 8" (ss) fixed regex parsing issue with multiple qualifiers [gi] 9" (ss) additional factoring of keywords, globals, and members 10" Last Change: 2020 May 14 11" 2013 Jun 12: adjusted javaScriptRegexpString (Kevin Locke) 12" 2018 Apr 14: adjusted javaScriptRegexpString (LongJohnCoder) 13 14" tuning parameters: 15" unlet javaScript_fold 16 17if !exists("main_syntax") 18 " quit when a syntax file was already loaded 19 if exists("b:current_syntax") 20 finish 21 endif 22 let main_syntax = 'javascript' 23elseif exists("b:current_syntax") && b:current_syntax == "javascript" 24 finish 25endif 26 27let s:cpo_save = &cpo 28set cpo&vim 29 30 31syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained 32syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo 33syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)" 34syn region javaScriptComment start="/\*" end="\*/" contains=@Spell,javaScriptCommentTodo 35syn match javaScriptSpecial "\\\d\d\d\|\\." 36syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=javaScriptSpecial,@htmlPreproc 37syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=javaScriptSpecial,@htmlPreproc 38syn region javaScriptStringT start=+`+ skip=+\\\\\|\\`+ end=+`+ contains=javaScriptSpecial,javaScriptEmbed,@htmlPreproc 39 40syn region javaScriptEmbed start=+${+ end=+}+ contains=@javaScriptEmbededExpr 41 42syn match javaScriptSpecialCharacter "'\\.'" 43syn match javaScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>" 44syn region javaScriptRegexpString start=+[,(=+]\s*/[^/*]+ms=e-1,me=e-1 skip=+\\\\\|\\/+ end=+/[gimuys]\{0,2\}\s*$+ end=+/[gimuys]\{0,2\}\s*[+;.,)\]}]+me=e-1 end=+/[gimuys]\{0,2\}\s\+\/+me=e-1 contains=@htmlPreproc,javaScriptComment oneline 45 46syn keyword javaScriptConditional if else switch 47syn keyword javaScriptRepeat while for do in 48syn keyword javaScriptBranch break continue 49syn keyword javaScriptOperator new delete instanceof typeof 50syn keyword javaScriptType Array Boolean Date Function Number Object String RegExp 51syn keyword javaScriptStatement return with await 52syn keyword javaScriptBoolean true false 53syn keyword javaScriptNull null undefined 54syn keyword javaScriptIdentifier arguments this var let 55syn keyword javaScriptLabel case default 56syn keyword javaScriptException try catch finally throw 57syn keyword javaScriptMessage alert confirm prompt status 58syn keyword javaScriptGlobal self window top parent 59syn keyword javaScriptMember document event location 60syn keyword javaScriptDeprecated escape unescape 61syn keyword javaScriptReserved abstract boolean byte char class const debugger double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile async 62 63syn cluster javaScriptEmbededExpr contains=javaScriptBoolean,javaScriptNull,javaScriptIdentifier,javaScriptStringD,javaScriptStringS,javaScriptStringT 64 65if exists("javaScript_fold") 66 syn match javaScriptFunction "\<function\>" 67 syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend 68 69 syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>" 70 syn sync match javaScriptSync grouphere NONE "^}" 71 72 setlocal foldmethod=syntax 73 setlocal foldtext=getline(v:foldstart) 74else 75 syn keyword javaScriptFunction function 76 syn match javaScriptBraces "[{}\[\]]" 77 syn match javaScriptParens "[()]" 78endif 79 80if main_syntax == "javascript" 81 syn sync fromstart 82 syn sync maxlines=100 83 84 syn sync ccomment javaScriptComment 85endif 86 87" Define the default highlighting. 88" Only when an item doesn't have highlighting yet 89hi def link javaScriptComment Comment 90hi def link javaScriptLineComment Comment 91hi def link javaScriptCommentTodo Todo 92hi def link javaScriptSpecial Special 93hi def link javaScriptStringS String 94hi def link javaScriptStringD String 95hi def link javaScriptStringT String 96hi def link javaScriptCharacter Character 97hi def link javaScriptSpecialCharacter javaScriptSpecial 98hi def link javaScriptNumber javaScriptValue 99hi def link javaScriptConditional Conditional 100hi def link javaScriptRepeat Repeat 101hi def link javaScriptBranch Conditional 102hi def link javaScriptOperator Operator 103hi def link javaScriptType Type 104hi def link javaScriptStatement Statement 105hi def link javaScriptFunction Function 106hi def link javaScriptBraces Function 107hi def link javaScriptError Error 108hi def link javaScrParenError javaScriptError 109hi def link javaScriptNull Keyword 110hi def link javaScriptBoolean Boolean 111hi def link javaScriptRegexpString String 112 113hi def link javaScriptIdentifier Identifier 114hi def link javaScriptLabel Label 115hi def link javaScriptException Exception 116hi def link javaScriptMessage Keyword 117hi def link javaScriptGlobal Keyword 118hi def link javaScriptMember Keyword 119hi def link javaScriptDeprecated Exception 120hi def link javaScriptReserved Keyword 121hi def link javaScriptDebug Debug 122hi def link javaScriptConstant Label 123hi def link javaScriptEmbed Special 124 125 126 127let b:current_syntax = "javascript" 128if main_syntax == 'javascript' 129 unlet main_syntax 130endif 131let &cpo = s:cpo_save 132unlet s:cpo_save 133 134" vim: ts=8 135