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

Switch between coffee- and javascript in vim like a ninja

Problem

Coffeescript is not for everybody.

Solution

Code in coffeescript, commit javascript

How

How to code both..at 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 %:r.coffee ]] && js2coffee % > %:r.coffee<CR>:sp %:r.coffee<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](https://github.com/kchmck/vim-coffee-script). The :CoffeeWatch command is pretty handy.



comments powered by Disqus


All rights reserved by Leon van Kammen under this license