Customize json syntax highlights
This commit is contained in:
		
							parent
							
								
									9f478e8307
								
							
						
					
					
						commit
						e1f63ce57f
					
				@ -1,20 +1,2 @@
 | 
			
		||||
" Set custom fold expression
 | 
			
		||||
setlocal foldmethod=expr
 | 
			
		||||
setlocal foldexpr=JsonFold(v:lnum)
 | 
			
		||||
 | 
			
		||||
" Custom fold function
 | 
			
		||||
function! JsonFold(lnum)
 | 
			
		||||
  let l:line = getline(a:lnum)
 | 
			
		||||
 | 
			
		||||
  if l:line =~ '{' && l:line !~ '}' && l:line !~ '".*{.*"'
 | 
			
		||||
    return 'a1'
 | 
			
		||||
  elseif l:line =~ '[' && l:line !~ ']' && l:line !~ '".*].*"'
 | 
			
		||||
    return 'a1'
 | 
			
		||||
  elseif l:line =~ '}' && l:line !~ '{' && l:line !~ '".*}.*"'
 | 
			
		||||
    return 's1'
 | 
			
		||||
  elseif l:line =~ ']' && l:line !~ '[' && l:line !~ '".*[.*"'
 | 
			
		||||
    return 's1'
 | 
			
		||||
  endif
 | 
			
		||||
 | 
			
		||||
  return '='
 | 
			
		||||
endfunction
 | 
			
		||||
set conceallevel=2
 | 
			
		||||
set concealcursor=n
 | 
			
		||||
 | 
			
		||||
@ -1,5 +0,0 @@
 | 
			
		||||
" Override default group names
 | 
			
		||||
hi link jsonQuote String
 | 
			
		||||
hi link jsonKeyword Keyword
 | 
			
		||||
hi link jsonKeywordMatch Operator
 | 
			
		||||
hi link jsonNoise Operator
 | 
			
		||||
							
								
								
									
										33
									
								
								syntax/json.vim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								syntax/json.vim
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
if exists("b:current_syntax")
 | 
			
		||||
  finish
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
syn cluster jsonValue contains=jsonString,jsonNumber,jsonObject,jsonArray,jsonBoolean,jsonNull
 | 
			
		||||
 | 
			
		||||
syn region jsonString oneline matchgroup=jsonStringEnd start=+"+ skip=+\\"+ end=+"+ concealends contains=jsonCharacter contained
 | 
			
		||||
syn match jsonNumber '-\?\d\+\(\.\d\+\([eE][-+]\?\d\+\)\?\)\?' contained
 | 
			
		||||
syn region jsonObject fold matchgroup=jsonObjectEnd start='{' end='}' transparent contains=jsonName,jsonColon,jsonComma,@jsonValue
 | 
			
		||||
syn region jsonArray fold matchgroup=jsonArrayEnd start='\[' end='\]' transparent contains=jsonComma,@jsonValue
 | 
			
		||||
syn keyword jsonBoolean true false
 | 
			
		||||
syn keyword jsonNull null
 | 
			
		||||
 | 
			
		||||
syn match jsonCharacter +\\\(["\\\/bfnrt]\|u\x\x\x\x\)+ contained
 | 
			
		||||
syn region jsonName oneline matchgroup=jsonNameEnd start=+"+ skip=+\\"+ end=+"\ze:+ concealends contains=jsonCharacter contained
 | 
			
		||||
syn match jsonColon ':' contained
 | 
			
		||||
syn match jsonComma ',' contained
 | 
			
		||||
 | 
			
		||||
hi default link jsonString String
 | 
			
		||||
hi default link jsonStringEnd Conceal
 | 
			
		||||
hi default link jsonNumber Number
 | 
			
		||||
hi default link jsonObjectEnd Delimiter
 | 
			
		||||
hi default link jsonArrayEnd Delimiter
 | 
			
		||||
hi default link jsonBoolean Boolean
 | 
			
		||||
hi default link jsonNull Constant
 | 
			
		||||
 | 
			
		||||
hi default link jsonCharacter SpecialChar
 | 
			
		||||
hi default link jsonName Function
 | 
			
		||||
hi default link jsonNameEnd Conceal
 | 
			
		||||
hi default link jsonColon Delimiter
 | 
			
		||||
hi default link jsonComma Delimiter
 | 
			
		||||
 | 
			
		||||
let b:current_syntax = 'json'
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user