" Use tab for trigger completion with characters ahead and navigate. " NOTE: There's always complete item selected by default, you may want to enable " no select by `"suggest.noselect": true` in your configuration file. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by " other plugin before putting this into your config. inoremap <silent><expr> <TAB> \ coc#pum#visible() ? coc#pum#next(1) : \ CheckBackspace() ? "\<Tab>" : \ coc#refresh() inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
使用回车键选择当前候选
1 2 3 4 5 6 7 8 9
" Make <CR> to accept selected completion item or notify coc.nvim to format " <C-g>u breaks current undo, please make your own choice. inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction
使用Ctrl+space调出补全窗口
1 2 3 4 5 6
" Use <c-space> to trigger completion. if has('nvim') inoremap <silent><expr> <c-space> coc#refresh() else inoremap <silent><expr> <c-@> coc#refresh() endif
跳转到函数定义
1 2 3 4 5
" GoTo code navigation. 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)
使用K显示文档窗口
1 2 3 4 5 6 7 8 9 10
" Use K to show documentation in preview window. nnoremap <silent> K :call ShowDocumentation()<CR>
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
选择函数、类 文字对象
1 2 3 4 5 6 7 8 9 10
" Map function and class text objects " NOTE: Requires 'textDocument.documentSymbol' support from the language server. xmap if <Plug>(coc-funcobj-i) omap if <Plug>(coc-funcobj-i) xmap af <Plug>(coc-funcobj-a) omap af <Plug>(coc-funcobj-a) xmap ic <Plug>(coc-classobj-i) omap ic <Plug>(coc-classobj-i) xmap ac <Plug>(coc-classobj-a) omap ac <Plug>(coc-classobj-a)