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>
Written by Christian Schlensker
Related protips
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside