sponsor Vim development Vim logo Vim Book Ad

basic Tip #833: Google lookup as a contextual spell check and phrase verifier.

 tip karma   Rating -8/13, Viewed by 793 

created:   December 14, 2004 16:36      complexity:   basic
author:   http://mixedvolume.blogspot.com      as of Vim:   6.0

I started hacking vim + google apis yesterday to do phrase lookups
on google. Google is much better (but
slower than a dictionary) as a contextual speller/data verifier.

However here is something readymade by Danny O'Brien, from
http://www.oblomovka.com/entries/2003/04/16#1050554820

In your .vimrc, add these lines:

" ,g  - create google a href for word under cursor
map ,g <Esc>Bm`:r!ghref <cword><CR>"gdd``i<C-R><C-R>g<esc>dw
vmap ,g yvgvdm`:r!ghref '<C-R>=substitute(@0, "['\n]", " ", "g")<cr>'<cr>"gdd``i<C-R><C-R>g<Esc>

Now put this program somewhere in your PATH, saved as "ghref"

#!/usr/bin/python
##
# ghref - takes a string on command line, looks it up in google, outputs
#         the HTML for a hyperlink to the "I'm feeling lucky" URL
##
import google
import sys
import re
def main(argv):
    search=argv[0]
    data = google.doGoogleSearch(search)
    if (data.results[0].summary):
        title = data.results[0].summary
    else:
        title = data.results[0].title
        title = re.sub('</*b>','',title)
    print '<a href="%s" title="%s">%s</a>' % (data.results[0].URL, title, argv[0])

if __name__ == '__main__':
    main(sys.argv[1:])

 rate this tip  Life Changing Helpful Unfulfilling 

<<Remembering previous deletes/yanks | Word-wise cut, copy & paste >>

Additional Notes

Anonymous, December 17, 2004 5:43
I hate Google.
Anonymous, December 18, 2004 17:18
i love microsoft
Anonymous, December 19, 2004 10:32
Me too.

I love it that GMale scans and sells the contents of my emales.

I like it that googel tracks me via it's AdCents
Jack, December 20, 2004 10:48
Well Google works and M$ doesn't.
Both make money and you are funny.
Anonymous, December 22, 2004 15:48
Yeah u hav 2 c4ll it teh M$
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo