1

I have a file.conf that has jsonc data. I tried the following hints at the beginning of the file:

// vim: ft=jsonc

and

# vim: ft=jsonc

but it has no effect, the filetype is still set to conf.

I know I can give a command manually :set ft=jsonc, but how to make it work automatically?

NOTE: The file name cannot be changed.

5
  • Works for me. What do :set modeline? and :set modelines? say?
    – Friedrich
    Mar 1 at 20:58
  • 1
    nomodeline, modelines=5 Mar 1 at 21:05
  • Then :set modeline to make it work.
    – Friedrich
    Mar 1 at 21:06
  • Yes, this was it. Do you want to post an answer, or it is not worth it? Mar 1 at 21:09
  • I'm actually writing one right now but it's really up to you to decide. PS: glad it works.
    – Friedrich
    Mar 1 at 21:11

1 Answer 1

2

The "hints" you put in files to set Vim options are called modelines. You can read about them in :help auto-setting, item 3, or :help modeline immediately below.

For modelines to work, the modeline option needs to be set and the modelines option will give the number of lines that are searched from the beginning and end of each file. These are documented in :help 'modeline' and :help 'modelines' (note the single quotes), respectively.

You can add the following line to your vimrc to enable modeline evaluation

set modeline

If your modelines are not within the first or last 5 lines of your files, you will also need to increase the value of modelines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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