diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2023-04-22 16:00:43 +0200 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2023-04-22 16:00:43 +0200 |
| commit | 12aae5adeaa393eecb424e9ffdc458616b2083f1 (patch) | |
| tree | d78357d2a1104a0d46e4af0ea99b13d8560f6423 /README.md | |
| parent | ad45ecff60461377788220da3b6f0ca8006f24cb (diff) | |
| download | vim-ai-12aae5adeaa393eecb424e9ffdc458616b2083f1.tar.gz | |
custom commands documentation
Diffstat (limited to '')
| -rw-r--r-- | README.md | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -289,6 +289,41 @@ let g:vim_ai_complete = chat_engine_config let g:vim_ai_edit = chat_engine_config ``` +## Custom commands + +To create a custom command, you can call `AIRun`, `AIEditRun` and `AIChatRun` functions. See examples below: + +```vim +" custom command suggesting git commit message, takes no arguments +function! AIPromptCommitMessageFn() + let l:diff = system('git diff --staged') + let l:prompt = "generate a short commit message from the diff below:\n" . l:diff + let l:range = 0 + let l:config = { + \ "engine": "chat", + \ "options": { + \ "model": "gpt-3.5-turbo", + \ "initial_prompt": ">>> system\nyou are a code assistant", + \ "temperature": 1, + \ }, + \} + call vim_ai#AIRun(l:range, l:config, l:prompt) +endfunction +command! AIPromptCommitMessage call AIPromptCommitMessageFn() + +" custom command that provides a code review for selected code block +function! AIPromptCodeReviewFn(range) range + let l:prompt = "programming syntax is " . &filetype . ", review the code below" + let l:config = { + \ "options": { + \ "initial_prompt": ">>> system\nyou are a clean code expert", + \ }, + \} + '<,'>call vim_ai#AIChatRun(a:range, l:config, l:prompt) +endfunction +command! -range AIPromptCodeReview <line1>,<line2>call AIPromptCodeReviewFn(<range>) +``` + ## Important Disclaimer **Accuracy**: GPT is good at producing text and code that looks correct at first glance, but may be completely wrong. Be sure to thoroughly review, read and test all output generated by this plugin! |