I'm using a syntax highlight plugin for Nginx files. Its ftdetect looks like this:

au BufRead,BufNewFile *.nginx set ft=nginx
au BufRead,BufNewFile nginx*.conf set ft=nginx
au BufRead,BufNewFile *nginx.conf set ft=nginx
au BufRead,BufNewFile */etc/nginx/* set ft=nginx
au BufRead,BufNewFile */usr/local/nginx/conf/* set ft=nginx
au BufRead,BufNewFile */nginx/*.conf set ft=nginx

It works well with local configuration files, but when I open a file which is outside the list of predefined directories, there is no syntax highlighting, even when the file ends by the following line:

# vim: syntax=nginx ts=4 sw=4 sts=4

If, inside vim, I run :setf nginx, then the syntax is back.

How do I change ftdetect to be able to benefit from syntax highlighting automatically based on the presence of # vim: syntax=nginx?

1 Answer 1


The correct modeline syntax sets options, so

# vim: filetype=nginx ts=4 sw=4 sts=4

Or the short version ft

  • Unfortunately, the problem persists with filetype, as well as with ft (i.e. the syntax highlighting is off, and I have to type :setf nginx to get it. Dec 18, 2018 at 22:31
  • Are the tabstop settings being applied? It’s bizarre to me that setf works, since it shouldn’t change anything if a filetype has already been set. This would imply those files have no filetype.
    – D. Ben Knoble
    Dec 18, 2018 at 22:31
  • @ArseniMourzenko sorry meant to ping you there^
    – D. Ben Knoble
    Dec 19, 2018 at 4:45
  • Indeed, tabstop settings are ignored as well, the default settings being used. I tried to copy apache2.conf file to a different location and using a different name: same problem here, despite "# vim:..." at the end, it's not detected as Apache configuration file. Any idea what could cause this behavior? Or do you want me to accept your answer and open a separate question? Dec 19, 2018 at 20:22
  • 1
    Found it. You pointed me to the right direction by giving the official name of that thing at the last line. I searched for modeline; it appears that it wasn't enabled (and now that I enabled it in .vimrc, it works. Not sure if it was disabled by one of the plugins or not enabled by default, but at least it works now. Thank you. Dec 19, 2018 at 20:37

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.