Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Accept Keymaps #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ Examples:
}
```

4. Changing accept line keymap
```vim
let g:llama_config.accept_full_keymap = "<C-S>"
```

Please refer to `:help llama_config` or the [source](./autoload/llama.vim)
for the full list of options.

Expand Down
45 changes: 27 additions & 18 deletions autoload/llama.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,31 @@ highlight llama_hl_info guifg=#77ff2f ctermfg=119
" ring_scope: the range around the cursor position (in number of lines) for gathering chunks after FIM
" ring_update_ms: how often to process queued chunks in normal mode
"
" keymaps parameters:
"
" accept_full_keymap: accept full suggestion keymap, default: <Tab>
" accept_line_keymap: accept line suggestion keymap, default: <S-Tab>
" accept_word_keymap: accept word suggestion keymap, default: <C-B>
"
let s:default_config = {
\ 'endpoint': 'http://127.0.0.1:8012/infill',
\ 'api_key': '',
\ 'n_prefix': 256,
\ 'n_suffix': 64,
\ 'n_predict': 128,
\ 't_max_prompt_ms': 500,
\ 't_max_predict_ms': 500,
\ 'show_info': 2,
\ 'auto_fim': v:true,
\ 'max_line_suffix': 8,
\ 'max_cache_keys': 250,
\ 'ring_n_chunks': 16,
\ 'ring_chunk_size': 64,
\ 'ring_scope': 1024,
\ 'ring_update_ms': 1000,
\ 'endpoint': 'http://127.0.0.1:8012/infill',
\ 'api_key': '',
\ 'n_prefix': 256,
\ 'n_suffix': 64,
\ 'n_predict': 128,
\ 't_max_prompt_ms': 500,
\ 't_max_predict_ms': 500,
\ 'show_info': 2,
\ 'auto_fim': v:true,
\ 'max_line_suffix': 8,
\ 'max_cache_keys': 250,
\ 'ring_n_chunks': 16,
\ 'ring_chunk_size': 64,
\ 'ring_scope': 1024,
\ 'ring_update_ms': 1000,
\ 'accept_full_keymap': "<Tab>",
\ 'accept_line_keymap': "<S-Tab>",
\ 'accept_word_keymap': "<C-B>",
\ }

let llama_config = get(g:, 'llama_config', s:default_config)
Expand Down Expand Up @@ -885,9 +894,9 @@ function! s:fim_on_stdout(hash, cache, pos_x, pos_y, is_auto, job_id, data, even
endif

" setup accept shortcuts
inoremap <buffer> <Tab> <C-O>:call llama#fim_accept('full')<CR>
inoremap <buffer> <S-Tab> <C-O>:call llama#fim_accept('line')<CR>
inoremap <buffer> <C-B> <C-O>:call llama#fim_accept('word')<CR>
exe 'inoremap <buffer> ' . g:llama_config.accept_full_keymap . ' <C-O>:call llama#fim_accept(''full'')<CR>'
exe 'inoremap <buffer> ' . g:llama_config.accept_line_keymap . ' <C-O>:call llama#fim_accept(''line'')<CR>'
exe 'inoremap <buffer> ' . g:llama_config.accept_word_keymap . ' <C-O>:call llama#fim_accept(''word'')<CR>'

let s:hint_shown = v:true
endfunction
Expand Down
44 changes: 27 additions & 17 deletions doc/llama.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,25 @@ variable.
Currently the default config is:
>vim
let s:default_config = {
\ 'endpoint': 'http://127.0.0.1:8012/infill',
\ 'api_key': '',
\ 'n_prefix': 256,
\ 'n_suffix': 64,
\ 'n_predict': 128,
\ 't_max_prompt_ms': 500,
\ 't_max_predict_ms': 500,
\ 'show_info': 2,
\ 'auto_fim': v:true,
\ 'max_line_suffix': 8,
\ 'max_cache_keys': 250,
\ 'ring_n_chunks': 16,
\ 'ring_chunk_size': 64,
\ 'ring_scope': 1024,
\ 'ring_update_ms': 1000,
\ }
\ 'endpoint': 'http://127.0.0.1:8012/infill',
\ 'api_key': '',
\ 'n_prefix': 256,
\ 'n_suffix': 64,
\ 'n_predict': 128,
\ 't_max_prompt_ms': 500,
\ 't_max_predict_ms': 500,
\ 'show_info': 2,
\ 'auto_fim': v:true,
\ 'max_line_suffix': 8,
\ 'max_cache_keys': 250,
\ 'ring_n_chunks': 16,
\ 'ring_chunk_size': 64,
\ 'ring_scope': 1024,
\ 'ring_update_ms': 1000,
\ 'accept_full_keymap': "<Tab>",
\ 'accept_line_keymap': "<S-Tab>",
\ 'accept_word_keymap': "<C-B>",
\ }
<

- {endpoint} llama.cpp server endpoint
Expand Down Expand Up @@ -146,6 +149,13 @@ parameters for the ring-buffer with extra context:

- {ring_update_ms} how often to process queued chunks in normal mode

keymaps parameters:

- {accept_full_keymap} accept full suggestion keymap, default: <Tab>

- {accept_line_keymap} accept line suggestion keymap, default: <S-Tab>
- {accept_word_keymap} accept word suggestion keymap, default: <C-B>

Example:

1. Disable the inline info (vimscript):
Expand All @@ -167,10 +177,10 @@ Example:
n_prefix = 1024,
n_suffix= 1024,
auto_fim = false,
accept_full_keymap = "<C-S>",
}
end,
}
<

To adjust the colors for hint and info texts, `llama.vim` provides the
highlight group `llama_hl_hint` and `llama_hl_info`. You can modify these
Expand Down