2

Problem

I find the error highlighting really distracting, its not that I don't want it because it is really useful for spotting errors in JSON syntax, but, I really dislike that it highlights new strings I start typing as errors. Obviously, if I have just started typing it out it won't be syntactically correct. It also knocks my workflow confidence.

Possible solutions in order of difficulty (and elegance)

  1. Disable JSON error highlighting
  2. Map a key to toggle JSON highlighting on/off
  3. Disable JSON highlighting on the current line only if the current line has just been added (<CR> or o/O)

My attempt (solution 1)

According to the syntax.txt file:
To disable syntax highlighting of errors:  
  let g:vim_json_warnings = 0

I did this while in a JSON file but alas to no effect.

I also ran :echo g:vim_json_warnings in a new vim instance and got E121: Undefined variable: g:vim_json_warnings, which seemed a bit strange to me.

Am I doing something wrong or is this a bug? I am using vim 8.2 gui

Question

What did I do wrong and how would you do solution 2?
3
  • I think you have to set the variable before the syntax file loads, like in your vimrc – D. Ben Knoble Apr 2 at 13:11
  • 1
    Thanks, that works. This post shows a way to reload syntax files if you want to change it on-the-fly, simply :e – Ripytide Apr 2 at 15:45
  • 2
    No idea whether that's really what you want, nor the impact it has on performance, but maybe you could temporarily toggle the errors off when entering insert mode: 0x0.st/-bh5.txt – user938271 Apr 2 at 22:28
2

For (1), you need to change the value of g:vim_json_warnings before the syntax file runs, such as in your vimrc.

As you point out, there is a way to force the syntax files to reload on-demand, so you can change the variable and then :edit to have the changes take effect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.