diff options
Diffstat (limited to '')
| -rw-r--r-- | vim-ai.vim | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -1,18 +1,18 @@ let g:openaiToken = system("cat ~/.config/openai.token") function! AIRun(...) range - let selection = getline(a:firstline, a:lastline) + let prompt = getline(a:firstline, a:lastline) if a:0 - let instruction = a:1 . ":" - call insert(selection, instruction, 0) + " join arguments and prepend to the prompt + let instruction = join(a:000, ", ") . ":" + call insert(prompt, instruction, 0) endif let buff_lastline = line('$') - - call writefile(selection, "/tmp/vim-ai.temp") + let prompt = join(prompt, "\n") echo "Completing..." - let output = system("cat /tmp/vim-ai.temp | openai complete - -t " . g:openaiToken) + let output = system("echo " . shellescape(prompt) . " | openai complete - -t " . g:openaiToken) let output = trim(output) execute a:firstline . ',' . a:lastline . 'd' @@ -26,5 +26,3 @@ function! AIRun(...) range endfunction command! -range -nargs=? AI <line1>,<line2>call AIRun(<f-args>) -nnoremap <leader>o :call AIRun()<CR> -vnoremap <leader>o :call AIRun()<CR> |