javascriptvimcoffeescript

how to make vim automatically open .js as compiled .coffee and save back to .js


I've found how to compile js to coffe on write, but not how to compile js to coffe on read. Strikes me this might be awesome.

Is this possible or is there perhaps a good reason for this being a bad idea?


Solution

  • I can't say what the precise syntax would be, but if you have file-type specific autocommands enabled in vim, you should be able to hook the javascript -> coffee compiler to "execute just before buffer load". You should find information on that within vim, try "help autocmd". In there you should find something about "BufReadPre" and "FileReadPre", which should be just about right. Since you've already done it for write, you probably know the syntax to hook up the compiler to that autocmd better than I do from the top of my head.