3

I'm editing a file with the following pattern:

# stock comment
# stock comment
# stock comment
# stock comment
# stock comment

conf
conf

conf
conf

very_long_conf_line_xxxxxx (600+ chars)

It's the stock layout and the file name ends with .conf, so Vim picked it up with ft=conf. It's actually some Nginx configuration, so I inserted a modeline like this:

# stock comment
# stock comment
# stock comment
# stock comment
# stock comment
# vim: set filetype=nginx:

conf
conf

conf
conf

very_long_conf_line (600+ chars)

However, when opening the file again, it's still taken as ft=conf.

:verbose se ml? shows modeline and last set from ~/.vimrc line xx, and :verbose se ft? shows filetype=conf and last set from /usr/share/vim/vim81/filetype.vim.

Why isn't my mode line working? How do I get it to work?

I'm running Vim 8.1 from Ubuntu Eoan.

4

Vim only checks for "a number of lines at the beginning of the end of the file". By default, only the first and last 5 lines are checked.

From :help 'modeline':

If 'modeline' is on 'modelines' gives the number of lines that is checked for set commands

And from help: 'modelines':

'modelines' 'mls' number (default 5)

If you wish, you can

  • :set modelines to a larger number, or
  • place the modeline(s) at the beginning or end of the file.
| improve this answer | |
  • Well... if only the stock comment contained one less line :( – iBug Feb 12 at 14:25

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.