diff options
author | Oxbian <oxbian@mailbox.org> | 2025-02-04 19:34:35 -0500 |
---|---|---|
committer | Oxbian <oxbian@mailbox.org> | 2025-02-04 19:34:35 -0500 |
commit | 14779f654194f86b3cec6d89e3fef9e792d29026 (patch) | |
tree | 4967fb59a7d73883156fc0673bf2c17ce1d6ef7c | |
parent | e65597837ec3057989f6bc67d90e5c10d4f3d14e (diff) | |
download | vimrc-14779f654194f86b3cec6d89e3fef9e792d29026.tar.gz vimrc-14779f654194f86b3cec6d89e3fef9e792d29026.zip |
feat: working + clean linter/fixer/completion/LSP
-rw-r--r-- | README.md | 47 | ||||
-rw-r--r-- | coc-settings.json | 12 | ||||
-rw-r--r-- | conf/keymaps.vim | 43 | ||||
-rw-r--r-- | conf/plugins.vim | 57 |
4 files changed, 63 insertions, 96 deletions
@@ -33,8 +33,7 @@ files with git. ### LSP -- [CoC](https://github.com/neoclide/coc.nvim) a LSP plugin that work like VsCode -LSP, and in Node (yeah I don't like it too but no choice...). +- [ALE](https://github.com/dense-analysis) linters, fixers, completion & LSP ## Command & keybinds @@ -109,9 +108,9 @@ Keybinds: Hunks are the difference between your file and the git file. -### Coc (Linter, Formatter, Snippets) +### ALE (Linter, fixers, completion, LSP) -For help, use `:help coc`. +For help, use `:help ALE`. Key binds: - `<leader>gd` go to the definition, @@ -126,41 +125,29 @@ Key binds: ## Snippets -To have snippets autocompletion, I use Coc snippets settings. -The `install.sh` script add the `coc-settings.json` file to the right place for -having all snippets filepath configured. +TODO in ALE -Moreover, you'll need to install in vim a Coc Extension: +## Linters / fixers & LSP -```vim -:CocInstall coc-snippets -``` +Linters and fixers needed to be installed for each language used. -## Linters & fixers +### Python -The following table shows the extensions I use for linting. -You can install them with +For python, you need to have [python-lsp-server](https://github.com/python-lsp/python-lsp-server). + +It can be system wide, or just in a virtualenv. -```vim -:CocInstall <extension> +```bash +python3 -m venv .venv +source .venv/bin/activate +pip install pyton-lsp-server[all] ``` -| Language | Coc Extension | -|:----------:|:----------------:| -| JSON | coc-json | -| Markdown | coc-markdownlint | -| PHP | coc-phpls | -| HTML | coc-html | -| CSS | coc-css | -| Javascript | coc-tsserver | - ## Formatter -By default my `coc-settings.json` add autoformatting on save on each filetype, -you just need a LSP server for the filetype. - -But if it's not working you could use vim formatting `ggvG=`, `=` is vim command -for formatting text. +By default my config add autoformatting on save on each filetype, you just need a LSP server for the filetype. + +But if it's not working you could use vim formatting `ggvG=`, `=` is vim command for formatting text. ## VM diff --git a/coc-settings.json b/coc-settings.json deleted file mode 100644 index f9bb1a8..0000000 --- a/coc-settings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "snippets.userSnippetsDirectory": "~/.config/vim/snippets", - "snippets.ultisnips.directories": [ - "~/.config/vim/snippets" - ], - "snippets.textmateSnippetsRoots": [ - "~/.config/vim/snippets" - ], - "coc.preferences.formatOnSaveFiletypes": [ - "*" - ] -} diff --git a/conf/keymaps.vim b/conf/keymaps.vim index 066dd21..351520d 100644 --- a/conf/keymaps.vim +++ b/conf/keymaps.vim @@ -145,46 +145,3 @@ noremap <leader>sa zg " show the list of alternatives for the word noremap <leader>s? z= - -""""""""""""""""""" -" LSP -""""""""""""""""""" -inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>" - -" 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> pumvisible() ? coc#_select_confirm() : - \"\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" -let g:coc_snippet_next = '<tab>' - -nmap <silent> gp <Plug>(coc-diagnostic-prev) -nmap <silent> gn <Plug>(coc-diagnostic-next) - -" 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) - -" Use K to show documentation in preview window -nnoremap <silent> gh :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) - -nmap <leader>qf <Plug>(coc-fix-current) diff --git a/conf/plugins.vim b/conf/plugins.vim index 89ca4c3..bdfa5ea 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 'neoclide/coc.nvim', {'branch': 'release'} +Plug 'dense-analysis/ale' " Tools Plug 'ap/vim-css-color' " rgb, hex color preview @@ -35,7 +35,25 @@ filetype plugin indent on " Allow filetype detection, plugins, indentation " Configuration """"""""""""""""""""""""" " LSP -let g:coc_global_extensions = ['coc-json', 'coc-markdownlint'] " You can add other coc extensions here +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'] +\} + +let g:ale_fixers = { +\ 'python': ['black', 'isort', 'autopep8'] +\} " Netrw (filetree built-in vim) let g:netrw_keepdir = 0 " Reload buffer usefull when moving or removing file @@ -54,6 +72,21 @@ let g:currentmode={ \ 'Rv' : 'V·Replace ', \ '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 @@ -66,6 +99,7 @@ set statusline+=%{&readonly?'\ ':''} set statusline+=%=%y set statusline+=\ \|\ %{&fileencoding?&fileencoding:&encoding} set statusline+=\ \|\ [%{&fileformat}\] +set statusline+=\ \|\ %{LinterStatus()} " Line count and percentage set statusline+=\ \|\ %l:%c set statusline+=\ [%p%%]\ @@ -119,15 +153,16 @@ let g:which_key_map.h = { \ } " LSP key help +" Activer WhichKey pour ALE let g:which_key_map.g = { \ 'name' : '+LSP', - \ 'd' : 'go to definition', - \ 'n' : 'next diagnostic', - \ 'p' : 'previous diagnostic', - \ 'r' : 'go to reference', - \ 'R' : 'rename object', - \ 'y' : 'type definition', - \ 'i' : 'go to implementation', - \ 'h' : 'documentation', - \ 'f' : 'format document', + \ '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'], \ } |