summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--README.md20
-rw-r--r--autoload/vim_ai.vim24
-rw-r--r--autoload/vim_ai_config.vim7
-rw-r--r--doc/vim-ai.txt7
4 files changed, 50 insertions, 8 deletions
diff --git a/README.md b/README.md
index 99254c0..8b777f8 100644
--- a/README.md
+++ b/README.md
@@ -203,10 +203,11 @@ Below are listed all available configuration options, along with their default v
```vim
" :AI
+" - engine: complete | chat - see how to configure chat engine in the section below
" - options: openai config (see https://platform.openai.com/docs/api-reference/completions)
" - options.request_timeout: request timeout in seconds
" - options.selection_boundary: seleciton prompt wrapper (eliminates empty responses, see #20)
-" - engine: complete | chat - see how to configure chat engine in the section below
+" - ui.paste_mode: use paste mode (see more info in the Notes below)
let g:vim_ai_complete = {
\ "engine": "complete",
\ "options": {
@@ -216,13 +217,17 @@ let g:vim_ai_complete = {
\ "request_timeout": 20,
\ "selection_boundary": "#####",
\ },
+\ "ui": {
+\ "paste_mode": 1,
+\ },
\}
" :AIEdit
+" - engine: complete | chat - see how to configure chat engine in the section below
" - options: openai config (see https://platform.openai.com/docs/api-reference/completions)
" - options.request_timeout: request timeout in seconds
" - options.selection_boundary: seleciton prompt wrapper
-" - engine: complete | chat - see how to configure chat engine in the section below
+" - ui.paste_mode: use paste mode (see more info in the Notes below)
let g:vim_ai_edit = {
\ "engine": "complete",
\ "options": {
@@ -232,6 +237,9 @@ let g:vim_ai_edit = {
\ "request_timeout": 20,
\ "selection_boundary": "#####",
\ },
+\ "ui": {
+\ "paste_mode": 1,
+\ },
\}
" This prompt instructs model to work with syntax highlighting
@@ -250,6 +258,7 @@ END
" - 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.scratch_buffer_keep_open: re-use scratch buffer within the vim session
+" - ui.paste_mode: use paste mode (see more info in the Notes below)
let g:vim_ai_chat = {
\ "options": {
\ "model": "gpt-3.5-turbo",
@@ -264,8 +273,15 @@ let g:vim_ai_chat = {
\ "populate_options": 0,
\ "open_chat_command": "preset_below",
\ "scratch_buffer_keep_open": 0,
+\ "paste_mode": 1,
\ },
\}
+
+" Notes:
+" ui.paste_mode
+" - if disabled code indentation will work but AI doesn't always respond with a code block
+" therefore it could be messed up
+" - find out more in vim's help `:help paste`
```
### Using chat engine for completion and edits
diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim
index b274048..74d6afd 100644
--- a/autoload/vim_ai.vim
+++ b/autoload/vim_ai.vim
@@ -76,6 +76,18 @@ function! s:OpenChatWindow(open_conf)
execute l:open_cmd
endfunction
+function! s:set_paste(config)
+ if a:config['ui']['paste_mode']
+ setlocal paste
+ endif
+endfunction
+
+function! s:set_nopaste(config)
+ if a:config['ui']['paste_mode']
+ setlocal nopaste
+ endif
+endfunction
+
" Complete prompt
" - is_selection - <range> parameter
" - config - function scoped vim_ai_complete config
@@ -93,7 +105,7 @@ function! vim_ai#AIRun(is_selection, config, ...) range
let s:last_is_selection = a:is_selection
let l:cursor_on_empty_line = trim(join(l:lines, "\n")) == ""
- set paste
+ call s:set_paste(l:config)
if l:cursor_on_empty_line
execute "normal! " . a:lastline . "GA"
else
@@ -101,7 +113,7 @@ function! vim_ai#AIRun(is_selection, config, ...) range
endif
execute "py3file " . s:complete_py
execute "normal! " . a:lastline . "G"
- set nopaste
+ call s:set_nopaste(l:config)
endfunction
" Edit prompt
@@ -119,10 +131,10 @@ function! vim_ai#AIEditRun(is_selection, config, ...) range
let s:last_instruction = l:instruction
let s:last_is_selection = a:is_selection
- set paste
+ call s:set_paste(l:config)
execute "normal! " . a:firstline . "GV" . a:lastline . "Gc"
execute "py3file " . s:complete_py
- set nopaste
+ call s:set_nopaste(l:config)
endfunction
" Start and answer the chat
@@ -134,7 +146,7 @@ function! vim_ai#AIChatRun(is_selection, config, ...) range
let l:instruction = ""
let l:lines = getline(a:firstline, a:lastline)
- set paste
+ call s:set_paste(l:config)
if &filetype != 'aichat'
let l:chat_win_id = bufwinid(s:scratch_buffer_name)
if l:chat_win_id != -1
@@ -160,7 +172,7 @@ function! vim_ai#AIChatRun(is_selection, config, ...) range
let s:last_is_selection = a:is_selection
execute "py3file " . s:chat_py
- set nopaste
+ call s:set_nopaste(l:config)
endfunction
" Start a new chat
diff --git a/autoload/vim_ai_config.vim b/autoload/vim_ai_config.vim
index ca8273e..1ee85df 100644
--- a/autoload/vim_ai_config.vim
+++ b/autoload/vim_ai_config.vim
@@ -7,6 +7,9 @@ let g:vim_ai_complete_default = {
\ "request_timeout": 20,
\ "selection_boundary": "#####",
\ },
+\ "ui": {
+\ "paste_mode": 1,
+\ },
\}
let g:vim_ai_edit_default = {
\ "engine": "complete",
@@ -17,6 +20,9 @@ let g:vim_ai_edit_default = {
\ "request_timeout": 20,
\ "selection_boundary": "#####",
\ },
+\ "ui": {
+\ "paste_mode": 1,
+\ },
\}
let s:initial_chat_prompt =<< trim END
@@ -39,6 +45,7 @@ let g:vim_ai_chat_default = {
\ "scratch_buffer_keep_open": 0,
\ "populate_options": 0,
\ "code_syntax_enabled": 1,
+\ "paste_mode": 1,
\ },
\}
diff --git a/doc/vim-ai.txt b/doc/vim-ai.txt
index 73ce3b4..931d018 100644
--- a/doc/vim-ai.txt
+++ b/doc/vim-ai.txt
@@ -30,6 +30,9 @@ Options: >
\ "request_timeout": 20,
\ "selection_boundary": "#####",
\ },
+ \ "ui": {
+ \ "paste_mode": 1,
+ \ },
\}
Check OpenAI docs for more information:
@@ -51,6 +54,9 @@ Options: >
\ "request_timeout": 20,
\ "selection_boundary": "#####",
\ },
+ \ "ui": {
+ \ "paste_mode": 1,
+ \ },
\}
Check OpenAI docs for more information:
@@ -85,6 +91,7 @@ Options: >
\ "populate_options": 0,
\ "open_chat_command": "preset_below",
\ "scratch_buffer_keep_open": 0,
+ \ "paste_mode": 1,
\ },
\}