Skip to content

Instantly share code, notes, and snippets.

@spino327
Created April 23, 2018 17:23
Show Gist options
  • Save spino327/1896cad258a6dd956edf597c6960d886 to your computer and use it in GitHub Desktop.
Save spino327/1896cad258a6dd956edf597c6960d886 to your computer and use it in GitHub Desktop.
ginger.vim: vim script to use http://www.gingersoftware.com/proofreading-rephrase-for-app to perform grammar checks on text.
" based on https://github.com/mattn/ginger-vim
let s:endpoint = 'http://services.gingersoftware.com/Ginger/correct/json/GingerTheText'
let g:ginger_api_key = '6ae0c3a0-afdc-4532-a810-82ded0054236'
function! s:ginger(text)
if get(g:, 'ginger_api_key', '') == ''
throw 'g:ginger_api_key is not set'
endif
let res = webapi#json#decode(webapi#http#get(s:endpoint, {
\ 'lang': 'US',
\ 'clientVersion': '2.0',
\ 'apiKey': g:ginger_api_key,
\ '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>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment