Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active May 5, 2023 14:07
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/5457352 to your computer and use it in GitHub Desktop.
Save mattn/5457352 to your computer and use it in GitHub Desktop.
let s:endpoint = 'http://services.gingersoftware.com/Ginger/correct/json/GingerTheText'
let s:apikey = '6ae0c3a0-afdc-4532-a810-82ded0054236'
function! s:ginger(text)
let res = webapi#json#decode(webapi#http#get(s:endpoint, {
\ 'lang': 'US',
\ 'clientVersion': '2.0',
\ 'apiKey': s:apikey,
\ 'text': a:text}).content)
let i = 0
let correct = ''
echon "Mistake: "
for rs in res['LightGingerTheTextResult']
let [from, to] = [rs['From'], rs['To']]
if i < from
echon a:text[i : from-1]
let correct .= a:text[i : from-1]
endif
echohl WarningMsg
echon a:text[from : to]
echohl None
let correct .= rs['Suggestions'][0]['Text']
let i = to + 1
endfor
if i < len(a:text)
echon a:text[i :]
let correct .= a:text[i :]
endif
echo "Correct: ".correct
endfunction
command! -nargs=+ Ginger call s:ginger(<q-args>)
@mattn
Copy link
Author

mattn commented Apr 25, 2013

:Ginger ThiS is A tesT

ってやると

こうなります。

@camelmasa
Copy link

awesome.

@subosito
Copy link

Just created a ruby gem for the same purpose, see https://github.com/subosito/gingerice. Any feedbacks appreciated :)

@ggarza
Copy link

ggarza commented Apr 28, 2013

Nice. You should submit this to vim.org/scripts

@slankdev
Copy link

Nice. I am going to use. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment