*vim-ai.txt* Complete text using OpenAI API.
Author: Martin Bielik
License: see https://github.com/madox2/vim-ai/blob/main/LICENSE
INTRODUCTION *vim-ai*
This plugin can be used to generate code, edit text, brainstorm ideas,
translate, etc.
COMMANDS *vim-ai-commands*
To set-up key bindings and expamples see:
https://github.com/madox2/vim-ai
*:AI*
:AI complete the text on the current line
:AI {prompt} complete the prompt
(selection) :AI complete the selection
(selection) :AI {instruction} complete the selection using the instruction
Options: >
let g:vim_ai_complete = {
\ "engine": "complete",
\ "options": {
\ "model": "text-davinci-003",
\ "max_tokens": 1000,
\ "temperature": 0.1,
\ "request_timeout": 10,
\ },
\}
Check OpenAI docs for more infomration:
https://platform.openai.com/docs/api-reference/completions
*:AIEdit*
(selection)? :AIEdit edit the current line or the selection
(selection)? :AIEdit {instruction} edit the current line or the selection using
the instruction
Options: >
let g:vim_ai_edit = {
\ "engine": "complete",
\ "options": {
\ "model": "text-davinci-003",
\ "max_tokens": 1000,
\ "temperature": 0.1,
\ "request_timeout": 10,
\ },
\}
Check OpenAI docs for more infomration:
https://platform.openai.com/docs/api-reference/completions
*:AIChat*
:AIChat continue or start a new conversation.
(selection)? :AIChat {instruction}? start a new conversation given the selection,
the instruction or both
Options: >
let s:initial_chat_prompt =<< trim END
>>> system
You are a general assistant.
If you attach a code block add syntax type after ``` to enable syntax highlighting.
END
let g:vim_ai_chat = {
\ "options": {
\ "model": "gpt-3.5-turbo",
\ "max_tokens": 1000,
\ "temperature": 1,
\ "request_timeout": 10,
\ "initial_prompt": s:initial_chat_prompt,
\ },
\ "ui": {
\ "code_syntax_enabled": 1,
\ "populate_options": 0,
\ "open_chat_command": "below new | call vim_ai#MakeScratchWindow()",
\ },
\}
Check OpenAI docs for more infomration:
https://platform.openai.com/docs/api-reference/chat
*:AIRedo*
:AIRedo repeat last AI command in order to re-try
or get an alternative completion.
CONFIGURATION *vim-ai-config*
To customize the default configuration, initialize the config variable with
a selection of options: >
let g:vim_ai_chat = {
\ "options": {
\ "model": "gpt-4",
\ "temperature": 0.2,
\ },
\}
Or modify options directly during the vim session: >
let g:vim_ai_chat['options']['model'] = 'gpt-4'
let g:vim_ai_chat['options']['temperature'] = 0.2
You can also customize the options in the chat header: >
[chat-options]
model=gpt-4
temperature=0.2
>>> user
generate a paragraph of lorem ipsum
...
KEY BINDINGS
Examples how configure key bindins and customize commands: >
" complete text on the current line or in visual selection
nnoremap a :AI
xnoremap a :AI
" edit text with custom context
xnoremap s :AIEdit fix grammar and spelling
nnoremap s :AIEdit fix grammar and spelling
" trigger chat
xnoremap c :AIChat
nnoremap c :AIChat
" redo last AI command
nnoremap r :AIRedo
" command with custom context (vim-ai functions: AIRun, AIEditRun, AIChatRun)
command! -range -nargs=? AICode ,call AIRun(, "Programming syntax is " . &filetype . ", " . )
ABOUT *vim-ai-about*
Contributions are welcome on GitHub:
https://github.com/madox2/vim-ai