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