diff options
| author | Martin Bielik <martin.bielik@instea.sk> | 2024-12-17 19:32:00 +0100 |
|---|---|---|
| committer | Martin Bielik <martin.bielik@instea.sk> | 2024-12-17 19:34:38 +0100 |
| commit | 93cd92aa0bba2ac34df3b25b124790434a0cd8b0 (patch) | |
| tree | ee6ad32121821dee5000b0294b1c4c21ff6e95e3 | |
| parent | 8402371e6af33dcf6962ffbc8cd73be0e36f6812 (diff) | |
| download | vim-ai-93cd92aa0bba2ac34df3b25b124790434a0cd8b0.tar.gz | |
replace :AINew with default roles, closes #97
Diffstat (limited to '')
| -rw-r--r-- | README.md | 31 | ||||
| -rw-r--r-- | autoload/vim_ai.vim | 14 | ||||
| -rw-r--r-- | autoload/vim_ai_config.vim | 1 | ||||
| -rw-r--r-- | doc/vim-ai.txt | 5 | ||||
| -rw-r--r-- | plugin/vim-ai.vim | 2 | ||||
| -rw-r--r-- | roles-default.ini | 3 |
6 files changed, 27 insertions, 29 deletions
@@ -86,18 +86,19 @@ To use an AI command, type the command followed by an instruction prompt. You ca ============= Utilities ============= :AIRedo repeat last AI command -:AINewChat open new chat :help vim-ai ``` **Tip:** Press `Ctrl-c` anytime to cancel completion -**Tip:** Setup your own [key bindings](#key-bindings) or use command shortcuts - `:AIE`, `:AIC`, `:AIR` +**Tip:** Use command shortcuts - `:AIE`, `:AIC`, `:AIR` or setup your own [key bindings](#key-bindings) -**Tip:** A [custom role](#roles) {role} can be passed to the above commands by an initial parameter /{role}, for example `:AIEdit /grammar`. +**Tip:** Define and use [custom roles](#roles), e.g. `:AIEdit /grammar`. -**Tip:** Combine commands with a range `:help range`, for example to select the whole buffer - `:%AIE fix grammar` +**Tip:** Use pre-defined roles `/right`, `/below`, `/tab` to choose how chat is open, e.g. `:AIC /right` + +**Tip:** Combine commands with a range `:help range`, e.g. to select the whole buffer - `:%AIE fix grammar` If you are interested in more tips or would like to level up your Vim with more commands like [`:GitCommitMessage`](https://github.com/madox2/vim-ai/wiki/Custom-commands#suggest-a-git-commit-message) - suggesting a git commit message, visit the [Community Wiki](https://github.com/madox2/vim-ai/wiki). @@ -168,14 +169,6 @@ Each file's contents will be added to an additional `user` role message with the Supported chat roles are **`>>> system`**, **`>>> user`**, **`>>> include`** 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`. For example: `:AINewChat right`. - ### `:AIRedo` `:AIRedo` - repeat last AI command @@ -367,9 +360,10 @@ END " - options.enable_auth: enable authorization using openai key " - options.token_file_path: override global token configuration " - options.selection_boundary: selection prompt wrapper (eliminates empty responses, see #20) -" - ui.populate_options: put [chat-options] to the chat header " - ui.open_chat_command: preset (preset_below, preset_tab, preset_right) or a custom command +" - ui.populate_options: put [chat-options] to the chat header " - ui.scratch_buffer_keep_open: re-use scratch buffer within the vim session +" - ui.force_new_chat: force new chat window (used in chat opening roles e.g. `/tab`) " - ui.paste_mode: use paste mode (see more info in the Notes below) let g:vim_ai_chat = { \ "prompt": "", @@ -387,10 +381,11 @@ let g:vim_ai_chat = { \ "initial_prompt": s:initial_chat_prompt, \ }, \ "ui": { -\ "code_syntax_enabled": 1, -\ "populate_options": 0, \ "open_chat_command": "preset_below", \ "scratch_buffer_keep_open": 0, +\ "populate_options": 0, +\ "code_syntax_enabled": 1, +\ "force_new_chat": 0, \ "paste_mode": 1, \ }, \} @@ -429,17 +424,17 @@ Then you set up a custom role that points to the OpenRouter endpoint: ```ini [gemini] -options.token_file_path = ~/.config/vim-ai-openrouter.token +options.token_file_path = ~/.config/openrouter.token options.endpoint_url = https://openrouter.ai/api/v1/chat/completions options.model = google/gemini-exp-1121:free [llama] -options.token_file_path = ~/.config/vim-ai-openrouter.token +options.token_file_path = ~/.config/openrouter.token options.endpoint_url = https://openrouter.ai/api/v1/chat/completions options.model = meta-llama/llama-3.3-70b-instruct [claude] -options.token_file_path = ~/.config/vim-ai-openrouter.token +options.token_file_path = ~/.config/openrouter.token options.endpoint_url = https://openrouter.ai/api/v1/chat/completions options.model = anthropic/claude-3.5-haiku ``` diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim index f6cbed5..87c825c 100644 --- a/autoload/vim_ai.vim +++ b/autoload/vim_ai.vim @@ -210,6 +210,13 @@ function! vim_ai#AIEditRun(uses_range, config, ...) range abort endfunction function! s:ReuseOrCreateChatWindow(config) + let l:open_conf = a:config['ui']['open_chat_command'] + + if a:config['ui']['force_new_chat'] == '1' + call s:OpenChatWindow(l:open_conf, 1) + return + endif + if &filetype != 'aichat' " reuse chat in active window or tab let l:chat_win_ids = win_findbuf(bufnr(s:scratch_buffer_name)) @@ -238,7 +245,6 @@ function! s:ReuseOrCreateChatWindow(config) endif " open new chat window if no active buffer found - let l:open_conf = a:config['ui']['open_chat_command'] call s:OpenChatWindow(l:open_conf, 0) endif endfunction @@ -280,10 +286,8 @@ endfunction " Start a new chat " a:1 - optional preset shorcut (below, right, tab) -function! vim_ai#AINewChatRun(...) abort - let l:open_conf = a:0 > 0 ? "preset_" . a:1 : g:vim_ai_chat['ui']['open_chat_command'] - call s:OpenChatWindow(l:open_conf, 1) - call vim_ai#AIChatRun(0, {}) +function! vim_ai#AINewChatDeprecatedRun(...) + echoerr ":AINew is deprecated, use pre-configured roles `/tab`, `/below`, `/right` instead (e.g. `:AIChat /right`)" endfunction " Repeat last AI command diff --git a/autoload/vim_ai_config.vim b/autoload/vim_ai_config.vim index 7264ced..05b7459 100644 --- a/autoload/vim_ai_config.vim +++ b/autoload/vim_ai_config.vim @@ -75,6 +75,7 @@ let g:vim_ai_chat_default = { \ "scratch_buffer_keep_open": 0, \ "populate_options": 0, \ "code_syntax_enabled": 1, +\ "force_new_chat": 0, \ "paste_mode": 1, \ }, \} diff --git a/doc/vim-ai.txt b/doc/vim-ai.txt index 1747965..93ec3eb 100644 --- a/doc/vim-ai.txt +++ b/doc/vim-ai.txt @@ -150,11 +150,6 @@ Globbing is expanded out via `glob.gob` and relative paths to the current working directory (as determined by `getcwd()`) will be resolved to absolute paths. - *: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 648578a..c826e8c 100644 --- a/plugin/vim-ai.vim +++ b/plugin/vim-ai.vim @@ -7,5 +7,5 @@ endif command! -range -nargs=? -complete=customlist,vim_ai#RoleCompletionComplete AI <line1>,<line2>call vim_ai#AIRun(<range>, {}, <q-args>) command! -range -nargs=? -complete=customlist,vim_ai#RoleCompletionEdit AIEdit <line1>,<line2>call vim_ai#AIEditRun(<range>, {}, <q-args>) command! -range -nargs=? -complete=customlist,vim_ai#RoleCompletionChat AIChat <line1>,<line2>call vim_ai#AIChatRun(<range>, {}, <q-args>) -command! -nargs=? AINewChat call vim_ai#AINewChatRun(<f-args>) +command! -nargs=? AINewChat call vim_ai#AINewChatDeprecatedRun(<f-args>) command! AIRedo call vim_ai#AIRedoRun() diff --git a/roles-default.ini b/roles-default.ini index 1b653f6..c4b30ef 100644 --- a/roles-default.ini +++ b/roles-default.ini @@ -1,10 +1,13 @@ # predefined roles [right.chat] +ui.force_new_chat = 1 ui.open_chat_command = preset_right [below.chat] +ui.force_new_chat = 1 ui.open_chat_command = preset_below [tab.chat] +ui.force_new_chat = 1 ui.open_chat_command = preset_tab |