summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Bielik <mx.bielik@gmail.com>2023-04-22 17:29:58 +0200
committerMartin Bielik <mx.bielik@gmail.com>2023-04-22 17:29:58 +0200
commit27ee959366ab8b5aebc2d0db6f508ebdc84519b6 (patch)
tree93c1e27cc4a574e025564301cadefd02b7962d40
parent4b3f4339e643bb7cae9065fb4129bdbfaf0b2dcf (diff)
downloadvim-ai-27ee959366ab8b5aebc2d0db6f508ebdc84519b6.tar.gz
added AINewChat command
-rw-r--r--README.md11
-rw-r--r--autoload/vim_ai.vim21
-rw-r--r--doc/vim-ai.txt5
-rw-r--r--plugin/vim-ai.vim1
4 files changed, 33 insertions, 5 deletions
diff --git a/README.md b/README.md
index 5d47090..21fee30 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,8 @@ To use an AI command, type the command followed by an instruction prompt. You ca
```
:AI complete text
:AIEdit edit text
-:AIChat open/continue chat
+:AIChat continue or open new chat
+:AINewChat open new chat
:AIRedo repeat last AI command
:help vim-ai
@@ -119,6 +120,14 @@ You are a Clean Code expert, I have the following code, please refactor it in a
Supported chat roles are **`>>> system`**, **`>>> user`** and **`<<< assistant`**
+### `:AINewChat`
+
+`:AINewChat {preset shortname}?` - start a new conversation
+
+This command is used when you need to spawn a new chat in a specific way or in situation when `:AIChat` would normally continue conversation instead.
+
+As a parameter you put an open chat command preset shortcut - `below`, `tab` or `right`.
+
### `:AIRedo`
`:AIRedo` - repeat last AI command
diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim
index 5d8ee79..a87517d 100644
--- a/autoload/vim_ai.vim
+++ b/autoload/vim_ai.vim
@@ -69,6 +69,13 @@ function! s:MakePrompt(is_selection, lines, instruction, config)
return join([l:instruction, l:delimiter, l:selection], "")
endfunction
+function! s:OpenChatWindow(open_conf)
+ let l:open_cmd = has_key(g:vim_ai_open_chat_presets, a:open_conf)
+ \ ? g:vim_ai_open_chat_presets[a:open_conf]
+ \ : a:open_conf
+ execute l:open_cmd
+endfunction
+
" Complete prompt
" - is_selection - <range> parameter
" - config - function scoped vim_ai_complete config
@@ -137,10 +144,7 @@ function! vim_ai#AIChatRun(is_selection, config, ...) range
else
" open new chat window
let l:open_conf = g:vim_ai_chat['ui']['open_chat_command']
- let l:open_cmd = has_key(g:vim_ai_open_chat_presets, l:open_conf)
- \ ? g:vim_ai_open_chat_presets[l:open_conf]
- \ : l:open_conf
- execute l:open_cmd
+ call s:OpenChatWindow(l:open_conf)
endif
endif
@@ -159,6 +163,15 @@ function! vim_ai#AIChatRun(is_selection, config, ...) range
set nopaste
endfunction
+" Start a new chat
+" a:1 - optional preset shorcut (below, right, tab)
+function! vim_ai#AINewChatRun(...)
+ let l:open_conf = a:0 ? "preset_" . a:1 : g:vim_ai_chat['ui']['open_chat_command']
+ call s:OpenChatWindow(l:open_conf)
+ call vim_ai#AIChatRun(0, {})
+endfunction
+
+" Repeat last AI command
function! vim_ai#AIRedoRun()
execute "normal! u"
if s:last_command == "complete"
diff --git a/doc/vim-ai.txt b/doc/vim-ai.txt
index d4ce47e..73ce3b4 100644
--- a/doc/vim-ai.txt
+++ b/doc/vim-ai.txt
@@ -91,6 +91,11 @@ Options: >
Check OpenAI docs for more information:
https://platform.openai.com/docs/api-reference/chat
+ *:AINewChat*
+
+:AINewChat {preset shortname}? spawn a new conversation with a given open
+ chat preset - below, tab or right.
+
*:AIRedo*
:AIRedo repeat last AI command in order to re-try
diff --git a/plugin/vim-ai.vim b/plugin/vim-ai.vim
index 0afe72c..1d03177 100644
--- a/plugin/vim-ai.vim
+++ b/plugin/vim-ai.vim
@@ -7,4 +7,5 @@ endif
command! -range -nargs=? AI <line1>,<line2>call vim_ai#AIRun(<range>, {}, <f-args>)
command! -range -nargs=? AIEdit <line1>,<line2>call vim_ai#AIEditRun(<range>, {}, <f-args>)
command! -range -nargs=? AIChat <line1>,<line2>call vim_ai#AIChatRun(<range>, {}, <f-args>)
+command! -nargs=? AINewChat call vim_ai#AINewChatRun(<f-args>)
command! AIRedo call vim_ai#AIRedoRun()