Permalink
Browse files

add json support

  • Loading branch information...
epeli committed Mar 31, 2011
1 parent b88532e commit af16a6d77eeff814a5c0aa30180103564451bade
Showing with 81 additions and 1 deletion.
  1. +3 −0 bundle/json/README
  2. +77 −0 bundle/json/syntax/json.vim
  3. +1 −1 vimrc
View
@@ -0,0 +1,3 @@
+This is a mirror of http://www.vim.org/scripts/script.php?script_id=1945
+
+A simple highlighting file for JSON constructs.
@@ -0,0 +1,77 @@
+" Vim syntax file
+" Language: JSON
+" Maintainer: Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
+" Last Change: 2009-06-16
+" Version: 0.4
+" {{{1
+
+" Syntax setup {{{2
+" For version 5.x: Clear all syntax items
+" For version 6.x: Quit when a syntax file was already loaded
+
+if !exists("main_syntax")
+ if version < 600
+ syntax clear
+ elseif exists("b:current_syntax")
+ finish
+ endif
+ let main_syntax = 'json'
+endif
+
+" Syntax: Strings {{{2
+syn region jsonString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=jsonEscape
+" Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
+syn region jsonStringSQ start=+'+ skip=+\\\\\|\\"+ end=+'+
+
+" Syntax: Escape sequences {{{3
+syn match jsonEscape "\\["\\/bfnrt]" contained
+syn match jsonEscape "\\u\x\{4}" contained
+
+" Syntax: Strings should always be enclosed with quotes.
+syn match jsonNoQuotes "\<\a\+\>"
+
+" Syntax: Numbers {{{2
+syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
+
+" Syntax: An integer part of 0 followed by other digits is not allowed.
+syn match jsonNumError "-\=\<0\d\.\d*\>"
+
+" Syntax: Boolean {{{2
+syn keyword jsonBoolean true false
+
+" Syntax: Null {{{2
+syn keyword jsonNull null
+
+" Syntax: Braces {{{2
+syn match jsonBraces "[{}\[\]]"
+
+" Define the default highlighting. {{{1
+" For version 5.7 and earlier: only when not done already
+" For version 5.8 and later: only when an item doesn't have highlighting yet
+if version >= 508 || !exists("did_json_syn_inits")
+ if version < 508
+ let did_json_syn_inits = 1
+ command -nargs=+ HiLink hi link <args>
+ else
+ command -nargs=+ HiLink hi def link <args>
+ endif
+ HiLink jsonString String
+ HiLink jsonEscape Special
+ HiLink jsonNumber Number
+ HiLink jsonBraces Operator
+ HiLink jsonNull Function
+ HiLink jsonBoolean Boolean
+
+ HiLink jsonNumError Error
+ HiLink jsonStringSQ Error
+ HiLink jsonNoQuotes Error
+ delcommand HiLink
+endif
+
+let b:current_syntax = "json"
+if main_syntax == 'json'
+ unlet main_syntax
+endif
+
+" Vim settings {{{2
+" vim: ts=8 fdm=marker
View
2 vimrc
@@ -53,7 +53,7 @@ let maplocalleader = ";"
au BufNewFile,BufRead *.zcml setfiletype xml
au BufNewFile,BufRead *.pt setfiletype xml
au BufNewFile,BufRead *.coffee setfiletype coffee
-au BufNewFile,BufRead *.json setfiletype javascript
+au BufNewFile,BufRead *.json setfiletype json
au BufNewFile,BufRead *.ru setfiletype ruby
au BufNewFile,BufRead *.conf setfiletype conf
au BufNewFile,BufRead *.pde setfiletype arduino

0 comments on commit af16a6d

Please sign in to comment.