diumenge, d’octubre 03, 2010

ZenCoding and wget

I recently discovered ZenCoding.vim. It includes a nice feature for building an html anchor from an url; the anchor text is being directly retrieved from the web, specifically the <title> tag of the web page:

Say your file contains a line

http://www.amazon.com

If you position the cursor on the url and press (Crtl Y + a), ZenCoding transforms it into

<a href="http://www.amazon.com">Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs &amp; more</a>

Unfortunately, this feature relies on curl for retrieving information from the web. I use wget instead (for no reason, I just happen to know this tools and it suffices for my modest needs).

In order to get ZenCoding to work with wget you have to change two lines of code as follows:


"silent! exec '0r!curl -s -L "'.substitute(a:
url, '#.*', '', '').'"'

silent! exec '0r!
wget -q -O - "'.substitute(a:url, '#.*', '', '').'"'

and


"let hex = substitute(system('curl -s "'.
fn.'" | xxd -p'), '\n', '', 'g')

let hex = substitute(system('wget -q -O - "'.
fn.'" | xxd -p'), '\n', '', 'g')


At least this is what GNU wget running on Windows + Cygwin expects.



Update 05.10.2013

Emmet, the current incarnation of ZenCoding, makes this configuration even simpler. It defines a global variable than can be set in your .vimrc file:

let g:emmet_curl_command= 'wget -q -O - '

That's it. You are non longer required to touch the plugin's source code.