" coc.nvim 的配置, 来自于 https://github.com/neoclide/coc.nvim " Use <c-space> for trigger completion. inoremap <silent><expr> <c-space> coc#refresh() set hidden " Some servers have issues with backup files, see #649 set nobackup set nowritebackup " 使用 Microsoft Python Language Server 不然 coc.nvim 会警告 call coc#config("python.jediEnabled", v:false) call coc#config("smartf.wordJump", v:false) call coc#config("smartf.jumpOnTrigger", v:false) " https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary call coc#config("rust-analyzer.serverPath", "~/.cargo/bin/rust-analyzer") call coc#config('coc.preferences', { \ "autoTrigger": "always", \ "maxCompleteItemCount": 10, \ "codeLens.enable": 1, \ "diagnostic.virtualText": 1, \})
" coc.nvim 插件,用于支持 python java 等语言 let s:coc_extensions = [ \ 'coc-python', \ 'coc-java', \ 'coc-json', \ 'coc-css', \ 'coc-html', \ 'coc-word', \ 'coc-cmake', \ 'coc-dictionary', \ 'coc-rust-analyzer', \ 'coc-vimlsp', \ 'coc-ci', \ 'coc-snippets', \ 'coc-vimtex', \ 'coc-smartf', \] for extension in s:coc_extensions call coc#add_extension(extension) endfor inoremap <silent><expr> <TAB> \ pumvisible() ? "\<C-n>" : \ <SID>check_back_space() ? "\<TAB>" : \ coc#refresh() inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" function! s:check_back_space() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction " 方便在中文中间使用 w 和 b 移动 nmap <silent> w <Plug>(coc-ci-w) nmap <silent> b <Plug>(coc-ci-b)
" Use <cr> for confirm completion, `<C-g>u` means break undo chain at current position. " Coc only does snippet and additional edit on confirm. inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" " Remap keys for gotos 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) " Use K for show documentation in preview window nnoremap <silent> K :call <SID>show_documentation()<CR> function! s:show_documentation() if &filetype == 'vim' execute 'h '.expand('<cword>') else call CocAction('doHover') endif endfunction " Highlight symbol under cursor on CursorHold set updatetime=300 autocmd CursorHold * silent call CocActionAsync('highlight') autocmd CursorHoldI * sil call CocActionAsync('showSignatureHelp') " Remap for rename current word nmap <leader>rn <Plug>(coc-rename) " 注释掉,一般使用 `Space` `r` `f` 直接格式化整个文件 " Remap for format selected region " vmap <leader>f <Plug>(coc-format-selected) " nmap <leader>f <Plug>(coc-format-selected) augroup mygroup autocmd! " Setup formatexpr specified filetype(s). autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') " Update signature help on jump placeholder autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') augroup end " Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph vmap <leader>a <Plug>(coc-codeaction-selected) nmap <leader>a <Plug>(coc-codeaction-selected) " Remap for do codeAction of current line nmap <leader>ac <Plug>(coc-codeaction) " Fix autofix problem of current line nmap <leader>qf <Plug>(coc-fix-current) " Use `:Format` for format current buffer " command! -nargs=0 Format :call CocAction('format') call SpaceVim#custom#SPC('nnoremap', ['r', 'f'], "call CocAction('format')", 'format file with coc.nvim', 1) " Use `:Fold` for fold current buffer command! -nargs=? Fold :call CocAction('fold', <f-args>) " auto import for go on save autocmd BufWritePre *.go :call CocAction('runCommand', 'editor.action.organizeImport') " 这个和 SpaceVim 的 statusline/tabline 冲突了 " Add diagnostic info for https://github.com/itchyny/lightline.vim " let g:lightline = { " \ 'colorscheme': 'wombat', " \ 'active': { " \ 'left': [ [ 'mode', 'paste' ], " \ [ 'cocstatus', 'readonly', 'filename', 'modified' ] ] " \ }, " \ 'component_function': { " \ 'cocstatus': 'coc#status' " \ }, " \ }
" Using CocList " Show all diagnostics nnoremap <silent> <leader>d :<C-u>CocList diagnostics<cr>
" 下面是 ccls 提供的 LSP Extension " https://github.com/MaskRay/ccls/wiki/coc.nvim " Manage extensions " nnoremap <silent> <space>e :<C-u>CocList extensions<cr> " Show commands " nnoremap <silent> <space>c :<C-u>CocList commands<cr> " Find symbol of current document " nnoremap <silent> <space>o :<C-u>CocList outline<cr> " Search workspace symbols " nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr> " Do default action for next item. " nnoremap <silent> <space>j :<C-u>CocNext<CR> " Do default action for previous item. " nnoremap <silent> <space>k :<C-u>CocPrev<CR> " Resume latest coc list " nnoremap <silent> <space>p :<C-u>CocListResume<CR> nn <silent> xl :call CocLocations('ccls','$ccls/navigate',{'direction':'D'})<cr> nn <silent> xk :call CocLocations('ccls','$ccls/navigate',{'direction':'L'})<cr> nn <silent> xj :call CocLocations('ccls','$ccls/navigate',{'direction':'R'})<cr> nn <silent> xh :call CocLocations('ccls','$ccls/navigate',{'direction':'U'})<cr> noremap x <Nop> nn <silent> xb :call CocLocations('ccls','$ccls/inheritance')<cr> " bases of up to 3 levels nn <silent> xb :call CocLocations('ccls','$ccls/inheritance',{'levels':3})<cr> " derived nn <silent> xd :call CocLocations('ccls','$ccls/inheritance',{'derived':v:true})<cr> " derived of up to 3 levels nn <silent> xD :call CocLocations('ccls','$ccls/inheritance',{'derived':v:true,'levels':3})<cr> " caller nn <silent> xc :call CocLocations('ccls','$ccls/call')<cr> " callee nn <silent> xC :call CocLocations('ccls','$ccls/call',{'callee':v:true})<cr> " $ccls/member " member variables / variables in a namespace nn <silent> xm :call CocLocations('ccls','$ccls/member')<cr> " member functions / functions in a namespace nn <silent> xf :call CocLocations('ccls','$ccls/member',{'kind':3})<cr> " nested classes / types in a namespace nn <silent> xs :call CocLocations('ccls','$ccls/member',{'kind':2})<cr> nmap <silent> xt <Plug>(coc-type-definition)<cr> nn <silent> xv :call CocLocations('ccls','$ccls/vars')<cr> nn <silent> xV :call CocLocations('ccls','$ccls/vars',{'kind':1})<cr> nn xx x
|