In vim, how can I set the file type not only according to the extension, but according to the #! line at the beginning? For instance, I would like vim to recognize files as coffee-script files when they start with #!/usr/bin/env coffee

link|improve this question
feedback

1 Answer

Vim usually properly detects filetypes when the hash-bang does not use the "env" utility, and it has code to try to internally translate #!/usr/bin/env [...] lines to something it can handle as well. The problem is that $VIMRUNTIME/scripts.vim has no "coffee" pattern.

The good news is that you can add to Vim's detection without having to modify the distribution files. You simply add your own detection logic to ~/.vim/scripts.vim. See ":help new-filetype-scripts" for details. You may want to review the entire ":help new-filetype" section.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.