diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | autoload/vim_ai.vim | 28 | ||||
| -rw-r--r-- | doc/vim-ai.txt | 1 | ||||
| -rw-r--r-- | plugin/vim-ai.vim | 1 |
4 files changed, 31 insertions, 1 deletions
@@ -216,6 +216,7 @@ END " - options.initial_prompt: prompt prepended to every chat request " - ui.populate_options: put [chat-options] to the chat header " - ui.open_chat_command: customize how to open chat window +" - ui.scratch_buffer_keep_open: re-use scratch buffer within the vim session let g:vim_ai_chat = { \ "options": { \ "model": "gpt-3.5-turbo", @@ -228,6 +229,7 @@ let g:vim_ai_chat = { \ "code_syntax_enabled": 1, \ "populate_options": 0, \ "open_chat_command": "below new | call vim_ai#MakeScratchWindow()", +\ "scratch_buffer_keep_open": 0, \ }, \} diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim index 4957c5b..bfe4f3e 100644 --- a/autoload/vim_ai.vim +++ b/autoload/vim_ai.vim @@ -1,6 +1,32 @@ +" Configures ai-chat scratch window. +" - scratch_buffer_keep_open = 0 +" - opens new ai-chat every time +" - scratch_buffer_keep_open = 1 +" - opens last ai-chat buffer +" - keeps the buffer in the buffer list function! vim_ai#MakeScratchWindow() + let l:keep_open = g:vim_ai_chat['ui']['scratch_buffer_keep_open'] + if l:keep_open && bufexists("[AI chat]") + " reuse chat buffer + buffer \[AI chat\] + return + endif setlocal buftype=nofile - setlocal bufhidden=hide setlocal noswapfile setlocal ft=aichat + if l:keep_open + setlocal bufhidden=hide + else + setlocal bufhidden=wipe + endif + if bufexists("[AI chat]") + " spawn another window if chat already exist + let l:index = 2 + while bufexists("[AI chat " . l:index . "]") + let l:index += 1 + endwhile + execute "file [AI chat ". l:index . "]" + else + file [AI chat] + endif endfunction diff --git a/doc/vim-ai.txt b/doc/vim-ai.txt index 616e7a1..6b40374 100644 --- a/doc/vim-ai.txt +++ b/doc/vim-ai.txt @@ -81,6 +81,7 @@ Options: > \ "code_syntax_enabled": 1, \ "populate_options": 0, \ "open_chat_command": "below new | call vim_ai#MakeScratchWindow()", + \ "scratch_buffer_keep_open": 0, \ }, \} diff --git a/plugin/vim-ai.vim b/plugin/vim-ai.vim index 088ba3d..ff49697 100644 --- a/plugin/vim-ai.vim +++ b/plugin/vim-ai.vim @@ -39,6 +39,7 @@ let g:vim_ai_chat_default = { \ }, \ "ui": { \ "open_chat_command": "below new | call vim_ai#MakeScratchWindow()", +\ "scratch_buffer_keep_open": 0, \ "populate_options": 0, \ "code_syntax_enabled": 1, \ }, |