Coder of Salvation™   — programming / opensource / console / minimal

Switch between coffee- and javascript in vim like a ninja


Coffeescript is not for everybody.


Code in coffeescript, commit javascript


How to code the same time?

Install the tools using npm install -g js2coffee coffee-script

put this in your vimrc:

" easy expansion to js (>) and compressing to coffeescript (<)
vmap c< :!js2coffee<CR>
vmap c> :!coffee --no-header -b -p -s<CR>
nmap c< ggVG:!js2coffee<CR>
nmap c> ggVG:!coffee --no-header -b -p -s<CR>:%s/};/};^M/g<CR> 
nmap cc :! [[ \! -f ]] && js2coffee % ><CR>:sp<CR>                                                                                                               

Example: Selections

Selections are handy when you don't want .coffee files in your repo (*)

* = eventhough this is the adviced approach for modules, there are reasons to not want .coffee-files in your repo (clean commits).

Example: switching / converting files

My thoughts

This is awesome:

think in coffeescript when editing a javascriptfile.

Also check out the vim plugin for coffeescript]( The :CoffeeWatch command is pretty handy.

comments powered by Disqus

All rights reserved by Leon van Kammen under this license