json.vim (2152B)
1 " Vim syntax file 2 " Language: JSON 3 " Maintainer: Jeroen Ruigrok van der Werven <asmodai@in-nomine.org> 4 " Last Change: 2009-06-16 5 " Version: 0.4 6 " {{{1 7 8 " Syntax setup {{{2 9 " For version 5.x: Clear all syntax items 10 " For version 6.x: Quit when a syntax file was already loaded 11 12 if !exists("main_syntax") 13 if version < 600 14 syntax clear 15 elseif exists("b:current_syntax") 16 finish 17 endif 18 let main_syntax = 'json' 19 endif 20 21 " Syntax: Strings {{{2 22 syn region jsonString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=jsonEscape 23 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript. 24 syn region jsonStringSQ start=+'+ skip=+\\\\\|\\"+ end=+'+ 25 26 " Syntax: Escape sequences {{{3 27 syn match jsonEscape "\\["\\/bfnrt]" contained 28 syn match jsonEscape "\\u\x\{4}" contained 29 30 " Syntax: Strings should always be enclosed with quotes. 31 syn match jsonNoQuotes "\<\a\+\>" 32 33 " Syntax: Numbers {{{2 34 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" 35 36 " Syntax: An integer part of 0 followed by other digits is not allowed. 37 syn match jsonNumError "-\=\<0\d\.\d*\>" 38 39 " Syntax: Boolean {{{2 40 syn keyword jsonBoolean true false 41 42 " Syntax: Null {{{2 43 syn keyword jsonNull null 44 45 " Syntax: Braces {{{2 46 syn match jsonBraces "[{}\[\]]" 47 48 " Define the default highlighting. {{{1 49 " For version 5.7 and earlier: only when not done already 50 " For version 5.8 and later: only when an item doesn't have highlighting yet 51 if version >= 508 || !exists("did_json_syn_inits") 52 if version < 508 53 let did_json_syn_inits = 1 54 command -nargs=+ HiLink hi link <args> 55 else 56 command -nargs=+ HiLink hi def link <args> 57 endif 58 HiLink jsonString String 59 HiLink jsonEscape Special 60 HiLink jsonNumber Number 61 HiLink jsonBraces Operator 62 HiLink jsonNull Function 63 HiLink jsonBoolean Boolean 64 65 HiLink jsonNumError Error 66 HiLink jsonStringSQ Error 67 HiLink jsonNoQuotes Error 68 delcommand HiLink 69 endif 70 71 let b:current_syntax = "json" 72 if main_syntax == 'json' 73 unlet main_syntax 74 endif 75 76 " Vim settings {{{2 77 " vim: ts=8 fdm=marker