Skip to content

Instantly share code, notes, and snippets.

@drewdeponte
Created August 8, 2015 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save drewdeponte/a900322903197b8f4fe4 to your computer and use it in GitHub Desktop.
Save drewdeponte/a900322903197b8f4fe4 to your computer and use it in GitHub Desktop.
An attempt at implementing support for selecta in neovim
function! SelectaCommand(choice_command, selecta_args, vim_command)
let dict = { 'vim_command': a:vim_command, 'temps': { 'result': tempname() }, 'name': 'SelectaCommand' }
function! dict.on_exit(id, code)
bd! " close terminal buffer
if a:code == 0 " success
if filereadable(self.temps.result)
let l:selection = readfile(self.temps.result)[0]
echom "selecta: selected: ".selection
exec self.vim_command." ".l:selection
else
echom "selecta: error: can't read selection from (".self.temps.result.")"
endif
else
echom "selecta: error: command exited (".string(a:code).")"
endif
endfunction
call termopen(a:choice_command." | ~/.nvim/bin/selecta ".a:selecta_args." > ".dict.temps.result, dict)
startinsert
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment