Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .