Skip to content

Instantly share code, notes, and snippets.

@chew-z
Created April 7, 2017 10:13
Show Gist options
  • Save chew-z/00faa6cd54502ab5625646271c097536 to your computer and use it in GitHub Desktop.
Save chew-z/00faa6cd54502ab5625646271c097536 to your computer and use it in GitHub Desktop.
Omni completion for thesaurus in VIM
" Moby Project thesaurus integration for vim
" Author: Tom Kurth <tom@losthalo.org>
" Homepage: http://github.com/tomku/thesauri
" License: GPLv2
" Last Modified: Fri, 31 Mar 2017
fun! CompleteThesauri(findstart, base)
if a:findstart
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start - 1] !~ '\s'
let start -= 1
endwhile
return start
else
let prequery ="rg -N --color never \"^([\w\s]+)?" . a:base . "([\s\w]+)?,\" " . g:mobythesaurus_file . "| awk -F/ '{print $1}'"
let query ="rg -N --color never \"^" . a:base . ",\" " . g:mobythesaurus_file . "| tr \",\" \"\\n\" "
let output = system(query)
if v:shell_error > 1
return []
elseif v:shell_error == 1
return []
else
let matches = []
for m in split(output, "\n")
call add(matches, m)
endfor
return {'words': matches, 'refresh': 'always'}
endif
endif
endfun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment