Skip to content

Commit

Permalink
replace :AINew with default roles, closes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
madox2 committed Dec 17, 2024
1 parent 8402371 commit 93cd92a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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": "",
Expand All @@ -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,
\ },
\}
Expand Down Expand Up @@ -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
```
Expand Down
14 changes: 9 additions & 5 deletions autoload/vim_ai.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions autoload/vim_ai_config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
\ },
\}
Expand Down
5 changes: 0 additions & 5 deletions doc/vim-ai.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin/vim-ai.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 3 additions & 0 deletions roles-default.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 93cd92a

Please sign in to comment.