diff options
author | jet tsang zeon-git <zeon-git@jettsang.com> | 2024-02-02 09:41:13 +0800 |
---|---|---|
committer | jet tsang zeon-git <zeon-git@jettsang.com> | 2024-02-02 09:41:13 +0800 |
commit | 5769d1537d62295ce893af8d87c44c296365740a (patch) | |
tree | 65d8ac0f8ed347d91313491b06dc87c783771d2f | |
parent | init (diff) | |
download | myconf-5769d1537d62295ce893af8d87c44c296365740a.tar.gz myconf-5769d1537d62295ce893af8d87c44c296365740a.tar.bz2 myconf-5769d1537d62295ce893af8d87c44c296365740a.zip |
Signed-off-by: jet tsang zeon-git <zeon-git@jettsang.com>
-rw-r--r-- | vimrc | 69 |
1 files changed, 59 insertions, 10 deletions
@@ -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 <silent> <C-k> :call RangeCommentLine()<CR> noremap <silent> <C-l> :call UnCommentLine()<CR> vnoremap <silent> <C-l> :call RangeUnCommentLine()<CR> -" 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 <line1>,<line2>call CodeReviewFn(<range>) -" 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 <line1>,<line2>call AISyntaxFn(<range>, <f-args>) + +" AI Key mappings nnoremap <leader>a :AI<CR> xnoremap <leader>a :AI<CR> xnoremap <leader>s :AIEdit fix grammar and spelling<CR> @@ -197,9 +234,21 @@ xnoremap <leader>c :AIChat<CR> nnoremap <leader>c :AIChat<CR> nnoremap <leader>r :AIRedo<CR> +" Rust +let g:rustfmt_autosave = 1 + " Rust key mappings nmap <silent> gd <Plug>(coc-definition) nmap <silent> gy <Plug>(coc-type-definition) nmap <silent> gi <Plug>(coc-implementation) nmap <silent> gr <Plug>(coc-references) nnoremap <silent> K :call <SID>show_documentation()<CR> + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('<cword>') + else + call CocAction('doHover') + endif +endfunction + |