diff --git a/home/.config/nvim/coc-settings.json b/home/.config/nvim/coc-settings.json new file mode 100644 index 0000000..38ed7e2 --- /dev/null +++ b/home/.config/nvim/coc-settings.json @@ -0,0 +1,14 @@ +{ + "pairs.enableCharacters": [ + "(", + "[", + "{", + "'", + "\"", + "`" + ], + "diagnostic.checkCurrentLine": true, + "coc.preferences.formatOnSaveFiletypes": [ + "json" + ] +} diff --git a/home/.config/nvim/rc/plugins.d/coc.vim b/home/.config/nvim/rc/plugins.d/coc.vim index 8378ff3..f9d4d00 100644 --- a/home/.config/nvim/rc/plugins.d/coc.vim +++ b/home/.config/nvim/rc/plugins.d/coc.vim @@ -1 +1,88 @@ -let g:coc_global_extensions = ['coc-python', 'coc-json', 'coc-git', 'coc-html', 'coc-css'] +let g:coc_global_extensions = [ + \ 'coc-python', 'coc-json', 'coc-git', 'coc-html', 'coc-css', + \ 'coc-clangd', 'coc-cmake', 'coc-java', 'coc-sh', 'coc-toml', + \ 'coc-yaml', 'coc-omnisharp', 'coc-markdownlint', 'coc-pairs' + \ ] + +" Use tab for trigger completion with characters ahead and navigate. +" Use command ':verbose imap ' to make sure tab is not mapped by other plugin. +inoremap + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ coc#refresh() +inoremap pumvisible() ? "\" : "\" + + +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +" Use to trigger completion. +inoremap coc#refresh() + +" Use to confirm completion, `u` means break undo chain at current position. +" Coc only does snippet and additional edit on confirm. +inoremap pumvisible() ? "\" : "\u\" +" Or use `complete_info` if your vim support it, like: +" inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" + +" Use `[g` and `]g` to navigate diagnostics +nmap [g (coc-diagnostic-prev) +nmap ]g (coc-diagnostic-next) + +" Remap keys for gotos +nmap gd (coc-definition) +nmap gy (coc-type-definition) +nmap gi (coc-implementation) +nmap gr (coc-references) + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + else + call CocAction('doHover') + endif +endfunction + +" Remap for rename current word +nmap (coc-rename) + +" Remap for format selected region +xmap f (coc-format-selected) +nmap f (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: `aap` for current paragraph +xmap a (coc-codeaction-selected) +nmap a (coc-codeaction-selected) + +" Remap for do codeAction of current line +nmap ac (coc-codeaction) +" Fix autofix problem of current line +nmap qf (coc-fix-current) + +" Create mappings for function text object, requires document symbols feature of languageserver. +xmap if (coc-funcobj-i) +xmap af (coc-funcobj-a) +omap if (coc-funcobj-i) +omap af (coc-funcobj-a) + +" Use `:Format` to format current buffer +command! -nargs=0 Format :call CocAction('format') + +" Use `:Fold` to fold current buffer +command! -nargs=? Fold :call CocAction('fold', ) + +" use `:OR` for organize import of current buffer +command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') + +" Add status line support, for integration with other plugin, checkout `:h coc-status` +set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}