Skip to content

Instantly share code, notes, and snippets.

@llinfeng
Created November 4, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llinfeng/3744f309ce1e629218bdcf2c314e4095 to your computer and use it in GitHub Desktop.
Save llinfeng/3744f309ce1e629218bdcf2c314e4095 to your computer and use it in GitHub Desktop.
Use AutoHotKey + Google for spell-checking: in Gvim.exe (Vim on Windows)
; How it works? Well, when you type a single word with erranous spellings to Google, it way "Did you mean ...".
; This AHK script grab that piece of Google Suggestion and pass it back to the clipboard.
; Purpose: select the world to the left of the cursor, and correct using Google:
; Credits: AutoHotkey Community (Linfeng is not able to find the original source.)
; Please comment if you are able to find the source of those fantastic regex expressions
;; Usage: use Ctrl + Alt + Shift + H, to select the word to the left of your
;; active cursor, and replace it with whatever Google corrects it to be.
;; Warning: only work best for very-close, but wrong, spellings.
;; Hint on Vim usage: as long as you type a long-wrong-word, Google will try to correct, and the `cw` keystrokes towards the end of this script will convert that whole thing into something reasonable.
#IfWinActive ahk_exe gvim.exe
; Upgraded: select the world to the left of the cursor, and correct using Google:
^+!h::
send {esc}
send b
send viw
clipback := ClipboardAll
clipboard=
Send ^c
ClipWait, 0
UrlDownloadToFile % "https://www.google.com/search?q=" . clipboard, temp
FileRead, contents, temp
FileDelete temp
if (RegExMatch(contents, "(Showing results for|Did you mean:)</span>.*?>(.*?)</a>", match)) {
StringReplace, clipboard, match2, <b><i>,, All
StringReplace, clipboard, clipboard, </i></b>,, All
clipboard := RegExReplace(clipboard, "&#39;", "'")
clipboard := RegExReplace(clipboard, "&amp;", "&")
}
send cw
Send ^v
Sleep 500
clipboard := clipback
return
#IfWinActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment