Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -7,3 +7,4 @@
*.fuse_hidden*
*.pxm
*.DS_Store
+/video/*
View
5 ftplugin/json.vim
@@ -6,6 +6,11 @@ if !exists("g:vim_json_syntax_conceal")
let g:vim_json_syntax_conceal = 1
end
+"have warnings by default
+if !exists("g:vim_json_warnings")
+ let g:vim_json_warnings = 1
+end
+
"set concealcursor blank by default
"this should turn off the concealing in the current line (where the cursor is at),
"on all modes (normal, visual, insert)
View
2  json-test.json
@@ -3,7 +3,7 @@
{
unquotedKeyword:'singleQuotedString',
'singleQuotedKeyword':true,
- "decimalCantStartWithPeriod":.1
+ "decimalCantStartWithPeriod":.1,
"semicolonAtEndOfThisObject":"trailingComma",
};
View
10 readme.md
@@ -1,10 +1,11 @@
Better JSON for VIM
===================
+
*Distinct highlighting of keywords vs values, JSON-specific (non-JS) warnings, quote concealing.*
![JSON syntax coloring](http://farm8.staticflickr.com/7234/7185560283_102f6b753d.jpg)
Customization of Jeroen Ruigrok van der Werven's [vim-json highlighting script](http://www.vim.org/scripts/script.php?script_id=1945) with Rogerz Zhang's [indent script](https://github.com/vim-scripts/vim-json-bundle).
-[Pathogen-friendly.](https://github.com/tpope/vim-pathogen) [Vundle-friendly](https://github.com/gmarik/Vundle.vim) too, just [be sure](https://github.com/elzr/vim-json/issues/25) to use the relative path in your `.vimrc` setup: `Plugin 'elzr/vim-json'`.
+[Pathogen-friendly.](https://github.com/tpope/vim-pathogen) [Vundle-friendly too](https://github.com/elzr/vim-json/issues/25).
Specific customizations
-----------------------
@@ -14,10 +15,12 @@ Specific customizations
* *This requires Vim 7.3+.* To disable it add `let g:vim_json_syntax_conceal = 0` to your `.vimrc`.
* Added **folding** of `{...}` and `[...]` blocks. To enable it `:setlocal foldmethod=syntax` (do it permanently on the `ftplugin/json.vim` file).
* **JSON-specific warnings** (red highlights):
+ * Warn about single-quoted keywords.
* Warn about *decimals* smaller than 1 that don't start with a 0 (`.1` gives a warning, it should be `0.1`).
* Warn about *comments* and *trailing semicolons*.
* Warn about *[missing commas](https://github.com/elzr/vim-json/issues/18)* between elements of an object.
* Warn about *trailing commas* after the last element in arrays or objects.
+ * (This can be turned off with a `let g:vim_json_warnings=0` in your `vimrc`.)
* Recognize `.jsonp` file type. In [JSONP](http://stackoverflow.com/questions/2067472/what-is-jsonp-all-about), the wrapping function call at the beginning and closing semicolon are recognized.
Screenshots
@@ -39,7 +42,10 @@ Here's 2 compelling reasons:
2. **Distinct highlighting for keywords.** JSON is an extremely lightweight data format but at its core lies an inescapable conceptual distinction: there are keywords and there are values. There's nothing much to the format besides that, so we might as well display keywords and values differently. This is something that gets lost with Javascript-inspired syntax highlighters, which see keywords as just another string since JSON requires them double quoted. So JSON files remain an impenetrable, indistinct wall of text.
Common problems
-------------
+---------------
+
+This is the expected behavior:
+![showcase](http://i.imgur.com/cmL1GNc.gif)
Most trouble, little as it is, has to do with Vim's newfangled concealing, which most people aren't yet familiar with, as it was introduced as recently as Vim 7.3+. If you just don't care for concealing you can easily disable it adding `let g:vim_json_syntax_conceal = 0` to your `.vimrc`.
View
52 syntax/json.vim
@@ -43,32 +43,32 @@ syn match jsonEscape "\\["\\/bfnrt]" contained
syn match jsonEscape "\\u\x\{4}" contained
" Syntax: Numbers
-syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
+syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]"
" ERROR WARNINGS **********************************************
-"
-" Syntax: Strings should always be enclosed with quotes.
-syn match jsonNoQuotesError "\<[[:alpha:]]\+\>"
+if (g:vim_json_warnings == 1)
+ " Syntax: Strings should always be enclosed with quotes.
+ syn match jsonNoQuotesError "\<[[:alpha:]]\+\>"
-" 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: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
-syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+"
+ " Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
+ syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+"
-" Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
-syn match jsonCommentError "//.*"
-syn match jsonCommentError "\(/\*\)\|\(\*/\)"
+ " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
+ syn match jsonCommentError "//.*"
+ syn match jsonCommentError "\(/\*\)\|\(\*/\)"
-" Syntax: No semicolons in JSON
-syn match jsonSemicolonError ";"
+ " Syntax: No semicolons in JSON
+ syn match jsonSemicolonError ";"
-" 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 /"\zs\_s\+\ze"/
+ " 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"/
+endif
" ********************************************** END OF ERROR WARNINGS
" Allowances for JSONP: function call at the beginning of the file,
@@ -111,13 +111,15 @@ if version >= 508 || !exists("did_json_syn_inits")
HiLink jsonBoolean Boolean
HiLink jsonKeyword Label
- HiLink jsonNumError Error
- HiLink jsonCommentError Error
- HiLink jsonSemicolonError Error
- HiLink jsonTrailingCommaError Error
- HiLink jsonMissingCommaError Error
- HiLink jsonStringSQError Error
- HiLink jsonNoQuotesError Error
+ if (g:vim_json_warnings == 1)
+ HiLink jsonNumError Error
+ HiLink jsonCommentError Error
+ HiLink jsonSemicolonError Error
+ HiLink jsonTrailingCommaError Error
+ HiLink jsonMissingCommaError Error
+ HiLink jsonStringSQError Error
+ HiLink jsonNoQuotesError Error
+ endif
HiLink jsonQuote Quote
HiLink jsonNoise Noise
delcommand HiLink

No commit comments for this range

Something went wrong with that request. Please try again.