0

I have .zsh-theme files (from oh-my-zsh), but they are not syntax highlighted. I was able to get this done pretty easily with

autocmd BufEnter *.zsh-theme set filetype=sh

However, before I did that I tried adding a vim meta comment for a specific file

#vim: set filetype=sh

The addition of the # apparently makes vim detect the file as a conf file, but it seems that this command is ignored (i.e. it is not detected as a sh file in spite of the comment). Is there any reason this may be happening?

FDinoff
  • 30,689
  • 5
  • 75
  • 96
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405

2 Answers2

10

Get rid of the word set (and add a space after the comment symbol)

# vim: filetype=sh

This fits with the first form of modelines

There are two forms of modelines.  The first form:
        [text]{white}{vi:|vim:|ex:}[white]{options}

[text]                  any text or empty
{white}                 at least one blank character (<Space> or <Tab>)
{vi:|vim:|ex:}          the string "vi:", "vim:" or "ex:"
[white]                 optional white space
{options}               a list of option settings, separated with white space
                        or ':', where each part between ':' is the argument
                        for a ":set" command (can be empty)
FDinoff
  • 30,689
  • 5
  • 75
  • 96
6

The syntax for this type of modeline is:

[text]{white}{vi:|vim:|ex:}[white]se[t] {options}:[text]

That is, try adding a space before vim:, and a trailing colon:

# vim: set filetype=sh:

You can find everything about modelines in

glts
  • 21,808
  • 12
  • 73
  • 94
  • @FDinoff Hmm, isn't that just part of the syntax (I don't know why)? Also see the examples given in the help, `/* vim: set ai tw=75: */` ... – glts Aug 29 '13 at 14:28