I frequently develop on Ruby on Rails. With the recent inclusion of Tilt in RoR 3, we have file extensions like .scss.erb. How can I make the filetype = scss.erb in this case automatically, and the same for every file that has multiple extensions?
Edit: It should be scss.eruby in this case, as erb extension defaults to eruby filetype.
Edit: If it wasn’t clear, I’m looking for a way to make this work dynamically for all files with multiple extensions. For example, file foo.js.html should have a filetype of js.html.
Edit again: Prince Goulash’s answer doesn’t take the default filetype for a particular extension.
In your vimrc:
(see
:help ftdetect, section 2).EDIT
To set the filetype dyanamically for multiple extensions, this seems to work for me:
The
substitutecommand constructs the filtype by simply stripping all text from the filename before the first.. There may be a more sophisticated way…EDIT AGAIN
Here’s another attempt.
MultiExtensionFiletype()is function that uses the default filetype of the last part of the extension and prefixes it with the first part of the extension (i.e. the part sandwiched between the dots).The function must be called on a
BufReadPostevent so the initial filetype is set by ignoring the multiple extensions.Hopefully this answer is converging on something useful!