History Report a problem
Article Edit this page Discussion

Check spelling and phrases using Google search

From Vim Tips Wiki

(Redirected from VimTip833)
Jump to: navigation, search
 

Tip 833Previous TipNext Tip

Created: December 14, 2004 Complexity: basic Author: mixedvolume Minimum version: 6.0 Karma: -1/16 Imported from: Tip#833


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 for 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:])

[edit] Comments

 

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Check spelling and phrases using Google search"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation