-
-
Save brennovich/45c8c3422037e9f1cd9d to your computer and use it in GitHub Desktop.
An attempt at implementing support for selecta in neovim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works nicely, thanks for sharing!
No more missed keypresses 👍