summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorMartin Bielik <mx.bielik@gmail.com>2023-04-22 16:00:43 +0200
committerMartin Bielik <mx.bielik@gmail.com>2023-04-22 16:00:43 +0200
commit12aae5adeaa393eecb424e9ffdc458616b2083f1 (patch)
treed78357d2a1104a0d46e4af0ea99b13d8560f6423 /README.md
parentad45ecff60461377788220da3b6f0ca8006f24cb (diff)
downloadvim-ai-12aae5adeaa393eecb424e9ffdc458616b2083f1.tar.gz
custom commands documentation
Diffstat (limited to '')
-rw-r--r--README.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/README.md b/README.md
index c008081..91808de 100644
--- a/README.md
+++ b/README.md
@@ -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!