From fedd8aa228f64b92122c913b95a0d812d877d238 Mon Sep 17 00:00:00 2001 From: Christian Baer Date: Thu, 7 May 2020 09:40:50 +0200 Subject: [PATCH] Added better json syntax highlightning as submodule --- .gitmodules | 3 + .vim/colors/smyck.vim | 97 ++++++++++++++++++++++++ .vim/syntax/json.vim | 169 +++++++++++++++++++++++++++++------------- bootstrap.sh | 1 + init/vim-json | 1 + 5 files changed, 219 insertions(+), 52 deletions(-) create mode 100644 .vim/colors/smyck.vim create mode 160000 init/vim-json diff --git a/.gitmodules b/.gitmodules index f2c9740..9b16306 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "init/FiraCode"] path = init/FiraCode url = https://github.com/tonsky/FiraCode.git +[submodule "init/vim-json"] + path = init/vim-json + url = https://github.com/elzr/vim-json diff --git a/.vim/colors/smyck.vim b/.vim/colors/smyck.vim new file mode 100644 index 0000000..3891675 --- /dev/null +++ b/.vim/colors/smyck.vim @@ -0,0 +1,97 @@ +" ---------------------------------------------------------------------------- +" Vim color file +" Maintainer: John-Paul Bader +" Last Change: 2012 April +" License: Beer Ware +" ---------------------------------------------------------------------------- + +" Reset Highlighting +hi clear +if exists("syntax_on") + syntax reset +endif + +set background=dark +set linespace=3 + +let g:colors_name = "smyck" + +hi Normal cterm=none ctermbg=none ctermfg=15 gui=none guibg=#282828 guifg=#F7F7F7 +hi LineNr cterm=none ctermbg=none ctermfg=8 gui=none guibg=#282828 guifg=#8F8F8F +hi StatusLine cterm=none ctermbg=8 ctermfg=15 gui=none guibg=#5D5D5D guifg=#FBFBFB +hi StatusLineNC cterm=none ctermbg=15 ctermfg=8 gui=none guibg=#5D5D5D guifg=#FBFBFB +hi Search cterm=none ctermbg=6 ctermfg=15 gui=none guibg=#2EB5C1 guifg=#F7F7F7 +hi IncSearch cterm=none ctermbg=3 ctermfg=8 gui=none guibg=#F6DC69 guifg=#8F8F8F +hi ColumnMargin cterm=none ctermbg=0 gui=none guibg=#000000 +hi Error cterm=none ctermbg=1 ctermfg=15 gui=none guifg=#F7F7F7 +hi ErrorMsg cterm=none ctermbg=1 ctermfg=15 gui=none guifg=#F7F7F7 +hi Folded cterm=none ctermbg=8 ctermfg=2 gui=none guibg=#3B3B3B guifg=#90AB41 +hi FoldColumn cterm=none ctermbg=8 ctermfg=2 gui=none guibg=#3B3B3B guifg=#90AB41 +hi NonText cterm=bold ctermbg=none ctermfg=8 gui=bold guifg=#8F8F8F +hi ModeMsg cterm=bold ctermbg=none ctermfg=10 gui=none +hi Pmenu cterm=none ctermbg=8 ctermfg=15 gui=none guibg=#8F8F8F guifg=#F7F7F7 +hi PmenuSel cterm=none ctermbg=15 ctermfg=8 gui=none guibg=#F7F7F7 guifg=#8F8F8F +hi PmenuSbar cterm=none ctermbg=15 ctermfg=8 gui=none guibg=#F7F7F7 guifg=#8F8F8F +hi SpellBad cterm=none ctermbg=1 ctermfg=15 gui=none guifg=#F7F7F7 +hi SpellCap cterm=none ctermbg=4 ctermfg=15 gui=none guifg=#F7F7F7 +hi SpellRare cterm=none ctermbg=4 ctermfg=15 gui=none guifg=#F7F7F7 +hi SpellLocal cterm=none ctermbg=4 ctermfg=15 gui=none guifg=#F7F7F7 +hi Visual cterm=none ctermbg=15 ctermfg=8 gui=none guibg=#F7F7F7 guifg=#8F8F8F +hi Directory cterm=none ctermbg=none ctermfg=4 gui=none guibg=#242424 guifg=#88CCE7 +hi SpecialKey cterm=none ctermbg=none ctermfg=8 gui=none guifg=#8F8F8F +hi DiffAdd cterm=bold ctermbg=2 ctermfg=15 +hi DiffChange cterm=bold ctermbg=4 ctermfg=15 +hi DiffDelete cterm=bold ctermbg=1 ctermfg=15 +hi DiffText cterm=bold ctermbg=3 ctermfg=8 +hi MatchParen cterm=none ctermbg=6 ctermfg=15 gui=none guibg=#2EB5C1 guifg=#F7F7F7 +hi CursorLine cterm=none ctermbg=238 ctermfg=none gui=none guibg=#424242 +hi CursorColumn cterm=none ctermbg=238 ctermfg=none gui=none guibg=#424242 +hi Title cterm=none ctermbg=none ctermfg=4 gui=none guifg=#88CCE7 +hi VertSplit cterm=bold ctermbg=none ctermfg=8 gui=bold guibg=#282828 guifg=#8F8F8F +hi SignColumn cterm=bold ctermbg=none ctermfg=8 gui=bold guibg=#282828 guifg=#8F8F8F + +" ---------------------------------------------------------------------------- +" Syntax Highlighting +" ---------------------------------------------------------------------------- +hi Keyword cterm=none ctermbg=none ctermfg=10 gui=none guifg=#D1FA71 +hi Comment cterm=none ctermbg=none ctermfg=8 gui=none guifg=#8F8F8F +hi Delimiter cterm=none ctermbg=none ctermfg=15 gui=none guifg=#F7F7F7 +hi Identifier cterm=none ctermbg=none ctermfg=12 gui=none guifg=#96D9F1 +hi Structure cterm=none ctermbg=none ctermfg=12 gui=none guifg=#9DEEF2 +hi Ignore cterm=none ctermbg=none ctermfg=8 gui=none guifg=bg +hi Constant cterm=none ctermbg=none ctermfg=12 gui=none guifg=#96D9F1 +hi PreProc cterm=none ctermbg=none ctermfg=10 gui=none guifg=#D1FA71 +hi Type cterm=none ctermbg=none ctermfg=12 gui=none guifg=#96D9F1 +hi Statement cterm=none ctermbg=none ctermfg=10 gui=none guifg=#D1FA71 +hi Special cterm=none ctermbg=none ctermfg=6 gui=none guifg=#d7d7d7 +hi String cterm=none ctermbg=none ctermfg=3 gui=none guifg=#F6DC69 +hi Number cterm=none ctermbg=none ctermfg=3 gui=none guifg=#F6DC69 +hi Underlined cterm=none ctermbg=none ctermfg=magenta gui=underline guibg=#272727 +hi Symbol cterm=none ctermbg=none ctermfg=9 gui=none guifg=#FAB1AB +hi Method cterm=none ctermbg=none ctermfg=15 gui=none guifg=#F7F7F7 +hi Interpolation cterm=none ctermbg=none ctermfg=6 gui=none guifg=#2EB5C1 + +" Erlang +hi link erlangAtom Keyword +hi link erlangBitType Keyword + +hi link rubyBeginend Keyword +hi link rubyClass Keyword +hi link rubyModule Keyword +hi link rubyKeyword Keyword +hi link rubyOperator Method +hi link rubyIdentifier Keyword +hi link rubyClassVariable Symbol +hi link rubyInstanceVariable Constant +hi link rubyGlobalVariable Constant +hi link rubyClassVariable Method +hi link rubyConstant Constant +hi link rubySymbol Symbol +hi link rubyFunction Constant +hi link rubyControl Keyword +hi link rubyConditional Keyword +hi link rubyInterpolation Interpolation +hi link rubyInterpolationDelimiter Interpolation +hi link rubyRailsMethod Method + + diff --git a/.vim/syntax/json.vim b/.vim/syntax/json.vim index 0f5c900..8d35609 100644 --- a/.vim/syntax/json.vim +++ b/.vim/syntax/json.vim @@ -1,74 +1,139 @@ " Vim syntax file -" Language: JSON -" Maintainer: Jeroen Ruigrok van der Werven -" Last Change: 2009-06-16 -" Version: 0.4 -" {{{1 +" Language: JSON +" Maintainer: Eli Parra https://github.com/elzr/vim-json +" Last Change: 2014-12-20 Load ftplugin/json.vim -" Syntax setup {{{2 -" For version 5.x: Clear all syntax items -" For version 6.x: Quit when a syntax file was already loaded +" Reload the definition of g:vim_json_syntax_conceal +" see https://github.com/elzr/vim-json/issues/42 +runtime! ftplugin/json.vim if !exists("main_syntax") - if version < 600 - syntax clear - elseif exists("b:current_syntax") - finish - endif - let main_syntax = 'json' + 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 match jsonNoise /\%(:\|,\)/ -" Syntax: Escape sequences {{{3 +" NOTE that for the concealing to work your conceallevel should be set to 2 + +" Syntax: Strings +" Separated into a match and region because a region by itself is always greedy +syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString +if has('conceal') && g:vim_json_syntax_conceal == 1 + syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained +else + syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained +endif + +" Syntax: JSON does not allow strings with single quotes, unlike JavaScript. +syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+ + +" Syntax: JSON Keywords +" Separated into a match and region because a region by itself is always greedy +syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword +if has('conceal') && g:vim_json_syntax_conceal == 1 + syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contains=jsonEscape contained +else + syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contains=jsonEscape contained +endif + +" Syntax: Escape sequences 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 +syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]" -" Syntax: Numbers {{{2 -syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" +" ERROR WARNINGS ********************************************** +if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) + " Syntax: Strings should always be enclosed with quotes. + syn match jsonNoQuotesError "\<[[:alpha:]][[:alnum:]]*\>" + syn match jsonTripleQuotesError /"""/ -" Syntax: An integer part of 0 followed by other digits is not allowed. -syn match jsonNumError "-\=\<0\d\.\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: Decimals smaller than one should begin with 0 (so .1 should be 0.1). + syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+" -" Syntax: Null {{{2 -syn keyword jsonNull null + " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file + syn match jsonCommentError "//.*" + syn match jsonCommentError "\(/\*\)\|\(\*/\)" -" Syntax: Braces {{{2 -syn match jsonBraces "[{}\[\]]" + " Syntax: No semicolons in JSON + syn match jsonSemicolonError ";" -" 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 - else - command -nargs=+ HiLink hi def link + " Syntax: No trailing comma after the last element of arrays or objects + syn match jsonTrailingCommaError ",\_s*[}\]]" + + " Syntax: Watch out for missing commas between elements + syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/ + syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values + if (expand('%:e') !=? 'jsonl') + syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array endif - HiLink jsonString String - HiLink jsonEscape Special - HiLink jsonNumber Number - HiLink jsonBraces Operator - HiLink jsonNull Function - HiLink jsonBoolean Boolean + syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value +endif - HiLink jsonNumError Error - HiLink jsonStringSQ Error - HiLink jsonNoQuotes Error - delcommand HiLink +" ********************************************** END OF ERROR WARNINGS +" Allowances for JSONP: function call at the beginning of the file, +" parenthesis and semicolon at the end. +" Function name validation based on +" http://stackoverflow.com/questions/2008279/validate-a-javascript-function-name/2008444#2008444 +syn match jsonPadding "\%^[[:blank:]\r\n]*[_$[:alpha:]][_$[:alnum:]]*[[:blank:]\r\n]*(" +syn match jsonPadding ");[[:blank:]\r\n]*\%$" + +" Syntax: Boolean +syn match jsonBoolean /\(true\|false\)\(\_s\+\ze"\)\@!/ + +" Syntax: Null +syn keyword jsonNull null + +" Syntax: Braces +syn region jsonFold matchgroup=jsonBraces start="{" end=/}\(\_s\+\ze\("\|{\)\)\@!/ transparent fold +syn region jsonFold matchgroup=jsonBraces start="\[" end=/]\(\_s\+\ze"\)\@!/ transparent fold + +" Define the default highlighting. +if version >= 508 || !exists("did_json_syn_inits") + hi def link jsonPadding Operator + hi def link jsonString String + hi def link jsonTest Label + hi def link jsonEscape Special + hi def link jsonNumber Number + hi def link jsonBraces Delimiter + hi def link jsonNull Function + hi def link jsonBoolean Boolean + hi def link jsonKeyword Label + + if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) + hi def link jsonNumError Error + hi def link jsonCommentError Error + hi def link jsonSemicolonError Error + hi def link jsonTrailingCommaError Error + hi def link jsonMissingCommaError Error + hi def link jsonStringSQError Error + hi def link jsonNoQuotesError Error + hi def link jsonTripleQuotesError Error + endif + hi def link jsonQuote Quote + hi def link jsonNoise Noise endif let b:current_syntax = "json" if main_syntax == 'json' - unlet main_syntax -endif \ No newline at end of file + unlet main_syntax +endif + +" Vim settings +" vim: ts=8 fdm=marker + +" MIT License +" Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra +"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +"THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +"See https://twitter.com/elzr/status/294964017926119424 diff --git a/bootstrap.sh b/bootstrap.sh index d0ec908..e36e9b2 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -79,6 +79,7 @@ deploy) # Copy color vim scheme from init folder to .vim/colors cp init/Smyck-Color-Scheme/smyck.vim .vim/colors/smyck.vim + cp init/vim-json/json.vim .vim/syntax/json.vim df_deploy ;; diff --git a/init/vim-json b/init/vim-json new file mode 160000 index 0000000..3727f08 --- /dev/null +++ b/init/vim-json @@ -0,0 +1 @@ +Subproject commit 3727f089410e23ae113be6222e8a08dd2613ecf2