Created
March 19, 2023 20:18
-
-
Save cherryramatisdev/024146eed99ce8aa8a2c6daa0a75bdf0 to your computer and use it in GitHub Desktop.
My config of COC vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ________________ COC.NVIM ________ | |
let g:coc_global_extensions = ['coc-json', | |
\ 'coc-git', | |
\ 'coc-snippets', | |
\ 'coc-tsserver', | |
\ 'coc-eslint', | |
\ 'coc-rust-analyzer', | |
\ 'coc-cssmodules', | |
\ 'coc-marketplace', | |
\ 'coc-java', | |
\ ] | |
" 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>" | |
" Use <c-space> to trigger completion | |
inoremap <silent><expr> <c-o> coc#refresh() | |
" Use `[g` and `]g` to navigate diagnostics | |
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list | |
nmap <silent> [d <Plug>(coc-diagnostic-prev) | |
nmap <silent> ]d <Plug>(coc-diagnostic-next) | |
" GoTo code navigation | |
set tagfunc=CocTagFunc | |
nmap <silent> gT <Plug>(coc-type-definition) | |
nmap <silent> gI <Plug>(coc-implementation) | |
nmap <silent> gr <Plug>(coc-references) | |
" Use K to show documentation in preview window | |
nnoremap <silent> K :call ShowDocumentation()<CR> | |
function! ShowDocumentation() | |
if CocAction('hasProvider', 'hover') | |
call CocActionAsync('doHover') | |
else | |
call feedkeys('K', 'in') | |
endif | |
endfunction | |
" Symbol renaming | |
nmap rn <Plug>(coc-rename) | |
" Formatting selected code | |
xmap <leader>f <Plug>(coc-format-selected) | |
function! s:eslint_or_format() abort | |
let l:filetypes = ["typescript", "typescriptreact", "javascript", "javascriptreact"] | |
if index(l:filetypes, &filetype) >= 0 | |
execute "CocCommand eslint.executeAutofix" | |
else | |
execute "call CocActionAsync('format')" | |
endif | |
endfunction | |
nnoremap <expr> <silent> <leader>f <sid>eslint_or_format() | |
" Applying code actions to the selected code block | |
" Example: `<leader>aap` for current paragraph | |
xmap ga <Plug>(coc-codeaction-selected) | |
nmap ga <Plug>(coc-codeaction) | |
" Apply the most preferred quickfix action to fix diagnostic on the current line | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Remap keys for applying refactor code actions | |
xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) | |
nmap <silent> <leader>r <Plug>(coc-codeaction-refactor) | |
" Run the Code Lens action on the current line | |
nmap <leader>cl <Plug>(coc-codelens-action) | |
" 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) | |
" Remap <C-f> and <C-b> to scroll float windows/popups | |
if has('nvim-0.4.0') || has('patch-8.2.0750') | |
nnoremap <silent><nowait><expr> <C-d> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-d>" | |
nnoremap <silent><nowait><expr> <C-u> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-u>" | |
inoremap <silent><nowait><expr> <C-d> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<C-d>" | |
inoremap <silent><nowait><expr> <C-u> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<C-u>" | |
vnoremap <silent><nowait><expr> <C-d> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-d>" | |
vnoremap <silent><nowait><expr> <C-u> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-u>" | |
endif | |
" Add (Neo)Vim's native statusline support | |
" NOTE: Please see `:h coc-status` for integrations with external plugins that | |
" provide custom statusline: lightline.vim, vim-airline | |
set statusline=%f | |
set statusline+=\ %{coc#status()}%{get(b:,'coc_current_function','')} | |
set statusline+=%= | |
set statusline+=%y | |
" Manipulate hunks | |
nnoremap <silent><nowait> <leader>hp :CocCommand git.chunkInfo<cr> | |
nnoremap <silent><nowait> <leader>hs :CocCommand git.chunkStage<cr> | |
nnoremap <silent><nowait> <leader>hS :Gwrite<cr> | |
nnoremap <silent><nowait> <leader>hu :CocCommand git.chunkUnstage<cr> | |
nnoremap <silent><nowait> <leader>hU :CocCommand git.chunkUndo<cr> | |
nnoremap <silent><nowait> <leader>hc :Git commit -v --no-verify<cr> | |
nnoremap <silent><nowait> <leader>ha :Git commit --amend -v --no-verify<cr> | |
nnoremap ]c <Plug>(coc-git-nextchunk) | |
nnoremap [c <Plug>(coc-git-prevchunk) | |
" Snippets | |
let g:coc_snippet_next = '<c-k>' | |
let g:coc_snippet_prev = '<c-j>' | |
" Use <C-k> for both expand and jump (make expand higher priority.) | |
inoremap <C-k> <Plug>(coc-snippets-expand-jump) | |
" Use <leader>x for convert visual selected code to snippet | |
xmap <leader>x <Plug>(coc-convert-snippet) | |
" Show all diagnostics | |
nnoremap <silent><nowait> <leader>q :<C-u>CocDiagnostics<cr> | |
" Show commands | |
nnoremap <silent><nowait> <leader>oc :<C-u>CocList commands<cr> | |
" Find symbol of current document | |
nnoremap <silent><nowait> <leader>ds :<C-u>CocList outline<cr> | |
" Search workspace symbols | |
nnoremap <silent><nowait> <leader>ws :<C-u>CocList -I symbols<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment