Skip to content

Commit

Permalink
Added common problems section and now setting concealcursor to blank …
Browse files Browse the repository at this point in the history
…by default
  • Loading branch information
elzr committed Aug 28, 2013
1 parent 89791d5 commit 752e607
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ftplugin/json.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ if !exists("g:vim_json_syntax_conceal")
let g:vim_json_syntax_conceal = 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)
if !exists("g:vim_json_syntax_concealcursor")
let g:vim_json_syntax_concealcursor = ""
end

if has('conceal')
if (g:vim_json_syntax_conceal == 1)
"level 2 means concealed text gets completely hidden unless a
"replacement is defined (none is defined by us)
setlocal conceallevel=2
let &l:concealcursor = g:vim_json_syntax_concealcursor
else
"level 0 means text is shown normally = no concealing
setlocal conceallevel=0
Expand Down
2 changes: 1 addition & 1 deletion json-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ Here's 2 compelling reasons:
1. **All JSON is Javascript but NOT all Javascript is JSON.** So `{property:1}` is invalid because `property` does not have double quotes around it. `{'property':1}` is also invalid, because it's single quoted while the only thing that can placate the JSON specification is double quoting. JSON is even fuzzy enough that `{"property":.1}` is invalid too, because you should have of course written `{"property":0.1}`. Also, don't even think about [having comments](http://stackoverflow.com/questions/244777/can-i-comment-a-json-file) or semicolons, you guessed it: they're invalid. The point being that your syntax highlighter should warn you about these errors, in realtime, which is something that the Javascript highlighter doesn't (because in Javacript they're not errors!).

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
------------

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`.

Concealing is nice for viewing but when you want to edit it should get out of your way seamlessly so you can see the actual code. Thus the **default behavior** *should* be text shown normally on the line your cursor is at, on all modes (normal, visual, insert). If this isn't the case and the concealing doesn't go away (not even in insert mode), you most likely have an interfering plugin ([indentLine](https://github.com/Yggdroot/indentLine), for instance). You need to look at your `concealcursor` setting (which can be set through this plugin with `g:vim_json_syntax_concealcursor`).

It's a good idea to test drive with the files `json-test.json` and `jsonp-test.jsonp` first thing.

0 comments on commit 752e607

Please sign in to comment.