Last Updated: February 25, 2016
· wordofchristian

Paste Javascript snippet as Coffeescript into the current vim buffer

Often you find a snippet of javascript that you want to use but have to first convert it coffeescript. Forget waiting for to load. Now you can paste the javascript directly into a vim buffer and have it automagically converted into coffeescript:

1: Install

npm install -g js2coffee

2: Run this vim command

:read !pbpaste | js2coffee

This will take whatever is on the system clipboard, pipe it through js2coffee and append it to the cursor location in the current vim buffer.

This only works for OSX.

For linux see this

For windows (???).

3: (extra credit) Turn it into a handy command

Past this into your .vimrc

function! PasteAsCoffee()
  :read !pbpaste | js2coffee
:command! PasteAsCoffee :call PasteAsCoffee()

Now you can just call :PasteAsCoffee to get the same result as before.

You can even map it to a key command: :map <leader>pc :PasteAsCoffee<CR>