0

The vim modeline settings options words appear in selected in red in the first line :

# vim: set ft=json noet:

I'm using vim 7.4 on CentOS Linux 7.9.

How can I disable that ?

1 Answer 1

2

JSON does not have any comments. Hence, the line is malformed and highlighted as an error.

You can disable this by setting let g:vim_json_warnings = 0 before opening the file. However, an error still an error, and your JSON parser may not be happy about that.

P.S. So this also means that there's no good way to insert a modeline into arbitrary JSON file.

4
  • Oh I see. So I guess I'll put that command in my vimrc instead : autocmd BufNewFile,BufRead *.json set filetype=json. Thanks for your help.
    – SebMa
    Jun 29 at 12:25
  • @SebMa That should work by default. Check :filetype output and make sure to read :h filetype.txt.
    – Matt
    Jun 29 at 12:34
  • 1
    In case, json extension was not properly auto-detected in old version such as v7.4, you'd better add the filetype setting under "ftdetect" subdir, not into your vimrc. See :h ftdetect specifically for explanations.
    – Matt
    Jun 29 at 12:43
  • In the old VIM v7.4 there is no "json.vim", I had to add download it from VIM v8.0 and put it in my ~/.vim/syntax/. Thanks for the :h ftdetect, I'll look into.
    – SebMa
    Jun 29 at 13:01

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.