diff options
author | Oxbian <oxbian@mailbox.org> | 2025-07-23 23:26:46 +0200 |
---|---|---|
committer | Oxbian <oxbian@mailbox.org> | 2025-07-23 23:26:46 +0200 |
commit | 08dcec61aef0fed78b6d94ff97faeb1312d862e7 (patch) | |
tree | 7abd17969446bea404e0da87c24ea40319ba2368 | |
parent | 4a752828e3d9f1aaab6f16a07a0114417bf2f89e (diff) | |
download | vimrc-08dcec61aef0fed78b6d94ff97faeb1312d862e7.tar.gz vimrc-08dcec61aef0fed78b6d94ff97faeb1312d862e7.zip |
feat: using COC as LSP + linter + autocompletion
-rw-r--r-- | conf/keymaps.vim | 53 | ||||
-rw-r--r-- | conf/options.vim | 1 | ||||
-rw-r--r-- | conf/plugins.vim | 84 |
3 files changed, 82 insertions, 56 deletions
diff --git a/conf/keymaps.vim b/conf/keymaps.vim index 351520d..cf04181 100644 --- a/conf/keymaps.vim +++ b/conf/keymaps.vim @@ -145,3 +145,56 @@ noremap <leader>sa zg " show the list of alternatives for the word noremap <leader>s? z= + +"""""""""""""""""""" +" LSP +"""""""""""""""""""" + +nmap <silent><nowait> [g <Plug>(coc-diagnostic-prev) +nmap <silent><nowait> ]g <Plug>(coc-diagnostic-next) + +" GoTo code navigation +nmap <silent><nowait> gd <Plug>(coc-definition) +nmap <silent><nowait> gy <Plug>(coc-type-definition) +nmap <silent><nowait> gi <Plug>(coc-implementation) +nmap <silent><nowait> 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 + +" Highlight the symbol and its references when holding the cursor +autocmd CursorHold * silent call CocActionAsync('highlight') + +" Symbol renaming +nmap <leader>gR <Plug>(coc-rename) + +" Formatting selected code +xmap <leader>gf <Plug>(coc-format-selected) +nmap <leader>gf <Plug>(coc-format-selected) + +" Applying code actions to the selected code block +xmap <leader>ga <Plug>(coc-codeaction-selected) +nmap <leader>ga <Plug>(coc-codeaction-selected) + +" Remap keys for applying code actions at the cursor position +nmap <leader>gc <Plug>(coc-codeaction-cursor) +" Remap keys for apply code actions affect whole buffer +nmap <leader>gs <Plug>(coc-codeaction-source) +" Apply the most preferred quickfix action to fix diagnostic on the current line +nmap <leader>gqf <Plug>(coc-fix-current) + +" Remap keys for applying refactor code actions +nmap <silent> <leader>gr <Plug>(coc-codeaction-refactor) +xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) +nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) + +" Run the Code Lens action on the current line +nmap <leader>gcl <Plug>(coc-codelens-action) diff --git a/conf/options.vim b/conf/options.vim index 395ee52..f36ac55 100644 --- a/conf/options.vim +++ b/conf/options.vim @@ -78,6 +78,7 @@ set ffs=unix,dos,mac " Turn backup off, since most stuff is in SVN, git etc. anyway... set nobackup +set nowritebackup set noswapfile " Timeout diff --git a/conf/plugins.vim b/conf/plugins.vim index e2349f3..e56d72d 100644 --- a/conf/plugins.vim +++ b/conf/plugins.vim @@ -22,7 +22,7 @@ Plug 'liuchengxu/vim-which-key' " Show leader mapping cheatsheet Plug 'airblade/vim-gitgutter' " Git diff " Autocompletion, linter, syntax -Plug 'dense-analysis/ale' +Plug 'neoclide/coc.nvim', {'branch': 'release'} " Tools Plug 'ap/vim-css-color' " rgb, hex color preview @@ -35,37 +35,24 @@ filetype plugin indent on " Allow filetype detection, plugins, indentation " Configuration """"""""""""""""""""""""" " LSP -let g:ale_python_auto_virtualenv = 1 -let g:ale_completion_enabled = 1 -let g:ale_floating_preview = 1 " Show hover doc & detail in a popup -let g:ale_fix_on_save = 1 - -" Stop linting when writing -let g:ale_lint_on_text_changed = 'never' -let g:ale_lint_on_insert_leave = 0 -let g:ale_hover_cursor = 1 -let g:ale_set_balloons = 1 " Show error when mouse over it - -" Linters and fixers (don't forget to setup LSP as linters) -let g:ale_linters = { -\ 'python': ['pylsp', 'flake8', 'pylint', 'mypy'], -\ 'php': ['intelephense', 'phpcs', 'phpmd'], -\ 'rust': ['analyzer'], -\ 'html': ['vscodehtml', 'htmlhint', 'stylelint', 'eslint'], -\ 'css': ['vscodecss', 'stylelint'], -\ 'javascript': ['eslint'], -\} - -let g:ale_fixers = { -\ 'python': ['black', 'isort', 'autopep8'], -\ 'php': ['php_cs_fixer'], -\ 'rust': ['rustfmt'], -\ 'html': ['html-beautify'], -\ 'css': ['css-beautify'], -\ 'javascript': ['js-beautify'], -\} -let g:ale_html_htmlhint_use_global = 1 -let g:ale_html_stylehint_use_global = 1 +" Navigate with tab and shift tab in the list, and enter to confirm selection +inoremap <expr> <Tab> coc#pum#visible() ? coc#pum#next(1) : "\<Tab>" +inoremap <expr> <S-Tab> coc#pum#visible() ? coc#pum#prev(1) : "\<S-Tab>" +inoremap <expr> <cr> coc#pum#visible() ? coc#pum#confirm() : "\<CR>" + +" 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 + +" Highlight the symbol and its references when holding the cursor +autocmd CursorHold * silent call CocActionAsync('highlight') " Netrw (filetree built-in vim) let g:netrw_keepdir = 0 " Reload buffer usefull when moving or removing file @@ -85,20 +72,6 @@ let g:currentmode={ \ 'c' : 'Command ', \} -" Getting numbers of errors in ALE -function! LinterStatus() abort - let l:counts = ale#statusline#Count(bufnr('')) - - let l:all_errors = l:counts.error + l:counts.style_error - let l:all_non_errors = l:counts.total - l:all_errors - - return l:counts.total == 0 ? 'OK' : printf( - \ '%dW %dE', - \ all_non_errors, - \ all_errors - \) - -endfunction set laststatus=2 set statusline= " VIM Mode @@ -111,7 +84,7 @@ set statusline+=%{&readonly?'\ ':''} set statusline+=%=%y set statusline+=\ \|\ %{&fileencoding?&fileencoding:&encoding} set statusline+=\ \|\ [%{&fileformat}\] -set statusline+=\ \|\ %{LinterStatus()} +set statusline+=\ \|\ %{coc#status()}%{get(b:,'coc_current_function','')} " Line count and percentage set statusline+=\ \|\ %l:%c set statusline+=\ [%p%%]\ @@ -168,13 +141,12 @@ let g:which_key_map.h = { " Activer WhichKey pour ALE let g:which_key_map.g = { \ 'name' : '+LSP', - \ 'd' : [':ALEGoToDefinition', 'go to definition'], - \ 'n' : [':ALENext', 'next diagnostic'], - \ 'p' : [':ALEPrevious', 'previous diagnostic'], - \ 'r' : [':ALEFindReferences', 'go to reference'], - \ 'R' : [':ALERename', 'rename object'], - \ 'y' : [':ALEType', 'type definition'], - \ 'i' : [':ALEGoToImplementation', 'go to implementation'], - \ 'h' : [':ALEHover', 'documentation'], - \ 'f' : [':ALEFix', 'format document'], + \ 'R' : 'rename object', + \ 'f' : 'format selected code', + \ 'a' : 'code action selected', + \ 'c' : 'code action curseur', + \ 's' : 'code action buffer', + \ 'qf' : 'quickfix current line', + \ 'r' : 'refactor all', + \ 'cl' : 'codelens action', \ } |