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: 2006 Jun 19 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 26" Drop fold if it set but vim doesn't support it. 27if version < 600 && exists("javaScript_fold") 28 unlet javaScript_fold 29endif 30 31syn case ignore 32 33 34syn keyword javaScriptCommentTodo TODO FIXME XXX TBD contained 35syn match javaScriptLineComment "\/\/.*" contains=@Spell,javaScriptCommentTodo 36syn match javaScriptCommentSkip "^[ \t]*\*\($\|[ \t]\+\)" 37syn region javaScriptComment start="/\*" end="\*/" contains=@Spell,javaScriptCommentTodo 38syn match javaScriptSpecial "\\\d\d\d\|\\." 39syn region javaScriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=javaScriptSpecial,@htmlPreproc 40syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=javaScriptSpecial,@htmlPreproc 41 42syn match javaScriptSpecialCharacter "'\\.'" 43syn match javaScriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>" 44syn region javaScriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc 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 52syn keyword javaScriptBoolean true false 53syn keyword javaScriptNull null undefined 54syn keyword javaScriptIdentifier arguments this var 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 62 63if exists("javaScript_fold") 64 syn match javaScriptFunction "\<function\>" 65 syn region javaScriptFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend 66 67 syn sync match javaScriptSync grouphere javaScriptFunctionFold "\<function\>" 68 syn sync match javaScriptSync grouphere NONE "^}" 69 70 setlocal foldmethod=syntax 71 setlocal foldtext=getline(v:foldstart) 72else 73 syn keyword javaScriptFunction function 74 syn match javaScriptBraces "[{}\[\]]" 75 syn match javaScriptParens "[()]" 76endif 77 78syn sync fromstart 79syn sync maxlines=100 80 81if main_syntax == "javascript" 82 syn sync ccomment javaScriptComment 83endif 84 85" Define the default highlighting. 86" For version 5.7 and earlier: only when not done already 87" For version 5.8 and later: only when an item doesn't have highlighting yet 88if version >= 508 || !exists("did_javascript_syn_inits") 89 if version < 508 90 let did_javascript_syn_inits = 1 91 command -nargs=+ HiLink hi link <args> 92 else 93 command -nargs=+ HiLink hi def link <args> 94 endif 95 HiLink javaScriptComment Comment 96 HiLink javaScriptLineComment Comment 97 HiLink javaScriptCommentTodo Todo 98 HiLink javaScriptSpecial Special 99 HiLink javaScriptStringS String 100 HiLink javaScriptStringD String 101 HiLink javaScriptCharacter Character 102 HiLink javaScriptSpecialCharacter javaScriptSpecial 103 HiLink javaScriptNumber javaScriptValue 104 HiLink javaScriptConditional Conditional 105 HiLink javaScriptRepeat Repeat 106 HiLink javaScriptBranch Conditional 107 HiLink javaScriptOperator Operator 108 HiLink javaScriptType Type 109 HiLink javaScriptStatement Statement 110 HiLink javaScriptFunction Function 111 HiLink javaScriptBraces Function 112 HiLink javaScriptError Error 113 HiLink javaScrParenError javaScriptError 114 HiLink javaScriptNull Keyword 115 HiLink javaScriptBoolean Boolean 116 HiLink javaScriptRegexpString String 117 118 HiLink javaScriptIdentifier Identifier 119 HiLink javaScriptLabel Label 120 HiLink javaScriptException Exception 121 HiLink javaScriptMessage Keyword 122 HiLink javaScriptGlobal Keyword 123 HiLink javaScriptMember Keyword 124 HiLink javaScriptDeprecated Exception 125 HiLink javaScriptReserved Keyword 126 HiLink javaScriptDebug Debug 127 HiLink javaScriptConstant Label 128 129 delcommand HiLink 130endif 131 132let b:current_syntax = "javascript" 133if main_syntax == 'javascript' 134 unlet main_syntax 135endif 136 137" vim: ts=8 138