1

I'm using Vim 7.4. I have the following code in my ~/.vim/after/php.vim file:

" Just a hello message.
echomsg "Hello world!"

" Add heredoc syntax to CSS code in a php file.
syn region  phpHereDoc  matchgroup=Delimiter
  \ start="\(<<<\)\@<=\(\"\=\)\z(\(\I\i*\)\=\(css\)\c\(\i*\)\)\2$"
  \ end="^\z1\(;\=$\)\@="
  \ contained
  \ contains=@htmlCss, phpIdentifierSimply, phpIdentifier, phpIdentifierComplex, phpBackslashSequences, phpMethodsVar, @Spell
  \ keepend extend

If I create a file vim hello.php, how do I make sure that Vim will run this code? I've confirmed that ~/.vim/after is in my runtimepath, but I still am not getting the extra syntax highlighting or the "Hello world" echo message. And if I run the :scriptnames command, the file does not show up on the list. What am I missing?

1 Answer 1

3

Placing files in a after/ directory is not enough because Vim won't even try to source a syntax script there on its own. It will only try to source files under after/ftplugin/, after/syntax/, etc.

Since the file in question is a syntax script, it must be placed in a syntax/ or after/syntax/ directory. In this case:

~/.vim/after/syntax/php.vim

Note that syntax scripts won't and shouldn't be "sourced at startup" willy-nilly: they are only sourced when :help 'syntax' is set for a given buffer and thus can only show up in :scriptnames after a number of things happened, like you have started editing a file with the corresponding filetype.

Example:

  • $ vim~/.vim/after/syntax/php.vim not visible in :scriptnames.
  • $ vim a/b/foo.php~/.vim/after/syntax/php.vim visible in :scriptnames.
  • :e a/b/foo.php~/.vim/after/syntax/php.vim visible in :scriptnames.
1
  • 1
    Yep, that worked. Thank you!
    – MrSnrub
    Commented Aug 10 at 15:45

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.