diff --git a/home-manager/modules/neovim.nix b/home-manager/modules/neovim.nix index 1430184..9d37310 100644 --- a/home-manager/modules/neovim.nix +++ b/home-manager/modules/neovim.nix @@ -104,10 +104,68 @@ set undoreload=1000 endif + " COC + " Having longer updatetime (default is 4000 ms = 4s) leads to noticeable " delays and poor user experience set updatetime=300 + " 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 ' to make sure tab is not mapped by + " other plugin before putting this into your config + inoremap + \ coc#pum#visible() ? coc#pum#next(1) : + \ CheckBackspace() ? "\" : + \ coc#refresh() + inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" + + " Make to accept selected completion item or notify coc.nvim to format + " u breaks current undo, please make your own choice + inoremap coc#pum#visible() ? coc#pum#confirm() + \: "\u\\=coc#on_enter()\" + + function! CheckBackspace() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' + endfunction + + " Use to trigger completion + if has('nvim') + inoremap coc#refresh() + else + inoremap coc#refresh() + endif + + " Use `[g` and `]g` to navigate diagnostics + " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list + nmap [g (coc-diagnostic-prev) + nmap ]g (coc-diagnostic-next) + + " GoTo code navigation + nmap gd (coc-definition) + nmap gy (coc-type-definition) + nmap gi (coc-implementation) + nmap gr (coc-references) + + " Use K to show documentation in preview window + nnoremap K :call ShowDocumentation() + + 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 rn (coc-rename) + " Always show the signcolumn, otherwise it would shift the text each time " diagnostics appear/become resolved set signcolumn=yes