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: 2012 Oct 05 11 12" For version 5.x: Clear all syntax items 13" For version 6.x: Quit when a syntax file was already loaded 14" tuning parameters: 15" unlet javaScript_fold 16 17if !exists("main_syntax") 18 if version < 600 19 syntax clear 20 elseif exists("b:current_syntax") 21 finish 22 endif 23 let main_syntax = 'javascript' 24endif 25 26let s:cpo_save = &cpo 27set cpo&vim 28 29" Drop fold if it set but vim doesn't support it. 30if version < 600 && exists("javaScript_fold") 31 unlet javaScript_fold 32endif 33 34 35syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained 36syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo 37syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)" 38syn region javaScriptComment start="/\*" end="\*/" contains=@Spell,javaScriptCommentTodo 39syn match javaScriptSpecial "\\\d\d\d\|\\." 40syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=javaScriptSpecial,@htmlPreproc 41syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=javaScriptSpecial,@htmlPreproc 42 43syn match javaScriptSpecialCharacter "'\\.'" 44syn match javaScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>" 45syn region javaScriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline 46 47syn keyword javaScriptConditional if else switch 48syn keyword javaScriptRepeat while for do in 49syn keyword javaScriptBranch break continue 50syn keyword javaScriptOperator new delete instanceof typeof 51syn keyword javaScriptType Array Boolean Date Function Number Object String RegExp 52syn keyword javaScriptStatement return with 53syn keyword javaScriptBoolean true false 54syn keyword javaScriptNull null undefined 55syn keyword javaScriptIdentifier arguments this var let 56syn keyword javaScriptLabel case default 57syn keyword javaScriptException try catch finally throw 58syn keyword javaScriptMessage alert confirm prompt status 59syn keyword javaScriptGlobal self window top parent 60syn keyword javaScriptMember document event location 61syn keyword javaScriptDeprecated escape unescape 62syn 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 63 64if exists("javaScript_fold") 65 syn match javaScriptFunction "\<function\>" 66 syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend 67 68 syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>" 69 syn sync match javaScriptSync grouphere NONE "^}" 70 71 setlocal foldmethod=syntax 72 setlocal foldtext=getline(v:foldstart) 73else 74 syn keyword javaScriptFunction function 75 syn match javaScriptBraces "[{}\[\]]" 76 syn match javaScriptParens "[()]" 77endif 78 79syn sync fromstart 80syn sync maxlines=100 81 82if main_syntax == "javascript" 83 syn sync ccomment javaScriptComment 84endif 85 86" Define the default highlighting. 87" For version 5.7 and earlier: only when not done already 88" For version 5.8 and later: only when an item doesn't have highlighting yet 89if version >= 508 || !exists("did_javascript_syn_inits") 90 if version < 508 91 let did_javascript_syn_inits = 1 92 command -nargs=+ HiLink hi link <args> 93 else 94 command -nargs=+ HiLink hi def link <args> 95 endif 96 HiLink javaScriptComment Comment 97 HiLink javaScriptLineComment Comment 98 HiLink javaScriptCommentTodo Todo 99 HiLink javaScriptSpecial Special 100 HiLink javaScriptStringS String 101 HiLink javaScriptStringD String 102 HiLink javaScriptCharacter Character 103 HiLink javaScriptSpecialCharacter javaScriptSpecial 104 HiLink javaScriptNumber javaScriptValue 105 HiLink javaScriptConditional Conditional 106 HiLink javaScriptRepeat Repeat 107 HiLink javaScriptBranch Conditional 108 HiLink javaScriptOperator Operator 109 HiLink javaScriptType Type 110 HiLink javaScriptStatement Statement 111 HiLink javaScriptFunction Function 112 HiLink javaScriptBraces Function 113 HiLink javaScriptError Error 114 HiLink javaScrParenError javaScriptError 115 HiLink javaScriptNull Keyword 116 HiLink javaScriptBoolean Boolean 117 HiLink javaScriptRegexpString String 118 119 HiLink javaScriptIdentifier Identifier 120 HiLink javaScriptLabel Label 121 HiLink javaScriptException Exception 122 HiLink javaScriptMessage Keyword 123 HiLink javaScriptGlobal Keyword 124 HiLink javaScriptMember Keyword 125 HiLink javaScriptDeprecated Exception 126 HiLink javaScriptReserved Keyword 127 HiLink javaScriptDebug Debug 128 HiLink javaScriptConstant Label 129 130 delcommand HiLink 131endif 132 133let b:current_syntax = "javascript" 134if main_syntax == 'javascript' 135 unlet main_syntax 136endif 137let &cpo = s:cpo_save 138unlet s:cpo_save 139 140" vim: ts=8 141