From 5769d1537d62295ce893af8d87c44c296365740a Mon Sep 17 00:00:00 2001 From: jet tsang zeon-git Date: Fri, 2 Feb 2024 09:41:13 +0800 Subject: Refactor vimrc: update AI config, add custom commands, and adjust settings Signed-off-by: jet tsang zeon-git --- vimrc | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/vimrc b/vimrc index fed86ba..e10bce0 100644 --- a/vimrc +++ b/vimrc @@ -39,6 +39,7 @@ Plugin 'neoclide/coc.nvim', {'branch': 'master', 'do': 'npm ci'} call vundle#end() filetype plugin indent on +colorscheme blackboard syntax enable let g:airline#extensions#tabline#enabled = 1 @@ -126,9 +127,6 @@ vnoremap :call RangeCommentLine() noremap :call UnCommentLine() vnoremap :call RangeUnCommentLine() -" Color scheme -color blackboard - " TypeScript settings let g:typescript_compiler_binary = 'tsc' let g:typescript_compiler_options = '' @@ -137,9 +135,6 @@ autocmd BufNewFile,BufRead *.ts set filetype=typescript autocmd FileType typescript :set makeprg=tsc autocmd BufNewFile,BufRead *.tsx,*.jsx set filetype=typescript.tsx -" Rust settings -let g:rustfmt_autosave = 1 - " AI integration let g:vim_ai_complete = { \ "options": { @@ -172,8 +167,8 @@ let chat_engine_config = { \ "options": { \ "endpoint_url": "https://api.openai.com/v1/chat/completions", \ "model": "gpt-4-turbo-preview", -\ "max_tokens": 128000, -\ "temperature": 0.1, +\ "max_tokens": 4096, +\ "temperature": 0.7, \ "request_timeout": 30, \ "selection_boundary": "", \ "initial_prompt": initial_prompt, @@ -184,11 +179,53 @@ let g:vim_ai_complete = chat_engine_config let g:vim_ai_edit = chat_engine_config let g:vim_ai_debug = 1 -" Custom commands + +" custom command suggesting git commit message, takes no arguments +function! GitCommitMessageFn() + let l:diff = system('git --no-pager diff --staged') + let l:prompt = "generate a short commit message from the diff below:\n" . l:diff + let l:range = 0 + let l:config = { + \ "engine": "chat", + \ "options": { + \ "endpoint_url": "https://api.openai.com/v1/chat/completions", + \ "model": "gpt-4-turbo-preview", + \ "initial_prompt": ">>> system\nyou are a code assistant", + \ "request_timeout": 30, + \ "temperature": 0.7, + \ }, + \} + call vim_ai#AIRun(l:range, l:config, l:prompt) +endfunction command! GitCommitMessage call GitCommitMessageFn() + +" custom command that provides a code review for selected code block +function! CodeReviewFn(range) range + let l:prompt = "programming syntax is " . &filetype . ", review the code below" + let l:config = { + \ "options": { + \ "initial_prompt": ">>> system\nyou are a clean code expert", + \ }, + \} + '<,'>call vim_ai#AIChatRun(a:range, l:config, l:prompt) +endfunction command! -range CodeReview ,call CodeReviewFn() -" Key mappings +" custom command adding filetype to the instruction +function! AISyntaxFn(range, ...) range + let l:instruction = "programming language is " . &filetype + if a:0 + let l:instruction = l:instruction . " - " . a:1 + endif + if a:range + '<,'>call vim_ai#AIRun(a:range, {}, l:instruction) + else + call vim_ai#AIRun(a:range, {}, l:instruction) + endif +endfunction +command! -range -nargs=? AISyntax ,call AISyntaxFn(, ) + +" AI Key mappings nnoremap a :AI xnoremap a :AI xnoremap s :AIEdit fix grammar and spelling @@ -197,9 +234,21 @@ xnoremap c :AIChat nnoremap c :AIChat nnoremap r :AIRedo +" Rust +let g:rustfmt_autosave = 1 + " Rust key mappings nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) nnoremap K :call show_documentation() + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + else + call CocAction('doHover') + endif +endfunction + -- cgit v1.2.3