Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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