Last Updated: February 25, 2016
·
1.104K
· 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 http://js2coffee.org to load. Now you can paste the javascript directly into a vim buffer and have it automagically converted into coffeescript:

1: Install https://github.com/rstacruz/js2coffee

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.

NOTE:
This only works for OSX.

For linux see this https://coderwall.com/p/kdoqkq.

For windows (???).

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

Past this into your .vimrc

function! PasteAsCoffee()
  :read !pbpaste | js2coffee
endfunction
: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>