Search code examples
jsontypescriptvimneovimtsconfig

Getting Error on commented JSON lines on Neovim


enter image description here

Editing tsconfig.json file my neovim is a nightmare. All the commented section for this json file is highlighted in red color. Its only for json files.


Solution

  • tsconfig.json is not JSON. It is actually the poorly specified "JSON with Comments" or "JSONC", a variant of JSON created by Microsoft for their tooling.

    Unfortunately, Microsoft uses the .json extension for its JSONC files so editors where filetype is assigned based on the extension incorrectly assume the file is JSON. Vim actually supports JSONC but only for files with the .jsonc extension. Bummer.

    Options…

    1. Change the filetype manually:

      :set filetype=jsonc
      

      manual

    2. Add a :help modeline to your JSONC files:

      // vim: filetype=jsonc
      

      modeline

    3. Set up proper filetype detection by putting this file under ~/.vim/ftdetect/, as per this document.