vimmodeline

#vim: set only sort of working


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?


Solution

  • 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)