Skip to content

Instantly share code, notes, and snippets.

@brennovich
Forked from drewdeponte/selecta_command.vim
Last active November 29, 2016 14:44
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 brennovich/45c8c3422037e9f1cd9d to your computer and use it in GitHub Desktop.
Save brennovich/45c8c3422037e9f1cd9d 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 = { 'buf': bufnr('%'), 'vim_command': a:vim_command, 'temps': { 'result': tempname() }, 'name': 'SelectaCommand' }
function! dict.on_exit(id, code)
bd!
if a:code != 0
return 1
endif
if filereadable(self.temps.result)
let l:selection = readfile(self.temps.result)[0]
exec self.vim_command." ".l:selection
else
echom "selecta: error: can't read selection from (".self.temps.result.")"
endif
endfunction
if a:vim_command != ':e'
exec 'split '.dict.buf
endif
call termopen(a:choice_command." | selecta ".a:selecta_args." > ".dict.temps.result, dict)
setf dict
startinsert
endfunction
nnoremap <leader>p :call SelectaCommand("selecta-command", "", ":e")<cr>
@mikepjb
Copy link

mikepjb commented Nov 29, 2016

This works nicely, thanks for sharing!

No more missed keypresses 👍

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