diff --git a/.vimrc.keymap b/.vimrc.keymap index 529b0061..589b9286 100755 --- a/.vimrc.keymap +++ b/.vimrc.keymap @@ -31,3 +31,68 @@ map n :NERDTreeToggle " quickfix nmap q window:quickfix:toggle +" ack +cnoreabbrev Ack Ack! +nnoremap / :Ack! +nnoremap [q :cprevious +nnoremap ]q :cnext + +" coc +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + else + call CocAction('doHover') + endif +endfunction +inoremap + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ coc#refresh() +inoremap pumvisible() ? "\" : "\" +inoremap coc#refresh() + +if exists('*complete_info') + inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" +else + inoremap pumvisible() ? "\" : "\u\" +endif + +nmap [g (coc-diagnostic-prev) +nmap ]g (coc-diagnostic-next) + +nmap gd (coc-definition) +nmap gy (coc-type-definition) +nmap gi (coc-implementation) +nmap gr (coc-references) + +nnoremap K :call show_documentation() +nmap rn (coc-rename) +xmap f (coc-format-selected) +nmap f (coc-format-selected) +xmap a (coc-codeaction-selected) +nmap a (coc-codeaction-selected) + +nmap ac (coc-codeaction) +nmap qf (coc-fix-current) + +xmap if (coc-funcobj-i) +xmap af (coc-funcobj-a) +omap if (coc-funcobj-i) +omap af (coc-funcobj-a) + +nmap (coc-range-select) +xmap (coc-range-select) +nnoremap a :CocList diagnostics +nnoremap e :CocList extensions +nnoremap c :CocList commands +nnoremap o :CocList outline +nnoremap s :CocList -I symbols +nnoremap j :CocNext +nnoremap k :CocPrev +nnoremap p :CocListResume diff --git a/.vimrc.plugins-settings b/.vimrc.plugins-settings index 323a1210..051c7cc3 100644 --- a/.vimrc.plugins-settings +++ b/.vimrc.plugins-settings @@ -24,80 +24,11 @@ autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in let g:rainbow_active = 1 " coc -set updatetime=300 - -" Some servers have issues with backup files, see #649. -set nobackup -set nowritebackup - -" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable -" delays and poor user experience. -set updatetime=300 - -" Don't pass messages to |ins-completion-menu|. set shortmess+=c - -" Always show the signcolumn, otherwise it would shift the text each time -" diagnostics appear/become resolved. set signcolumn=yes -" Use tab for trigger completion with characters ahead and navigate. -" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by -" other plugin before putting this into your config. -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. -" could be remapped by other vim plugin, try `:verbose imap `. -if exists('*complete_info') - inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" -else - inoremap pumvisible() ? "\" : "\u\" -endif - -" Use `[g` and `]g` to navigate diagnostics -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 show_documentation() - -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - else - call CocAction('doHover') - endif -endfunction - -" Highlight the symbol and its references when holding the cursor. autocmd CursorHold * silent call CocActionAsync('highlight') -" Symbol renaming. -nmap rn (coc-rename) - -" Formatting selected code. -xmap f (coc-format-selected) -nmap f (coc-format-selected) - augroup mygroup autocmd! " Setup formatexpr specified filetype(s). @@ -106,57 +37,13 @@ augroup mygroup autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') augroup end -" Applying codeAction to the selected region. -" Example: `aap` for current paragraph -xmap a (coc-codeaction-selected) -nmap a (coc-codeaction-selected) - -" Remap keys for applying codeAction to the current line. -nmap ac (coc-codeaction) -" Apply AutoFix to problem on the current line. -nmap qf (coc-fix-current) - -" Introduce function text object -" NOTE: Requires 'textDocument.documentSymbol' support from the language server. -xmap if (coc-funcobj-i) -xmap af (coc-funcobj-a) -omap if (coc-funcobj-i) -omap af (coc-funcobj-a) - -" Use for selections ranges. -" NOTE: Requires 'textDocument/selectionRange' support from the language server. -" coc-tsserver, coc-python are the examples of servers that support it. -nmap (coc-range-select) -xmap (coc-range-select) - -" Add `:Format` command to format current buffer. command! -nargs=0 Format :call CocAction('format') - -" Add `:Fold` command to fold current buffer. command! -nargs=? Fold :call CocAction('fold', ) - -" Add `:OR` command for organize imports of the current buffer. command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') -" 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^=%{coc#status()}%{get(b:,'coc_current_function','')} -" Mappings using CoCList: -" Show all diagnostics. -nnoremap a :CocList diagnostics -" Manage extensions. -nnoremap e :CocList extensions -" Show commands. -nnoremap c :CocList commands -" Find symbol of current document. -nnoremap o :CocList outline -" Search workspace symbols. -nnoremap s :CocList -I symbols -" Do default action for next item. -nnoremap j :CocNext -" Do default action for previous item. -nnoremap k :CocPrev -" Resume latest coc list. -nnoremap p :CocListResume +" ack +let g:ackprg = 'rg --vimgrep --smart-case' +let g:ack_autoclose = 1 +let g:ack_use_cword_for_empty_search = 1 diff --git a/.vimrc.settings b/.vimrc.settings index 3e534ba1..6ee1a2d3 100755 --- a/.vimrc.settings +++ b/.vimrc.settings @@ -5,6 +5,9 @@ set noswapfile set undofile set undodir=$HOME/.vim/undo set spell spelllang=en_gb +set updatetime=300 +set nobackup +set nowritebackup " buffers can be switched despite having changes set hidden diff --git a/nixos/home-manager/programs/vim.nix b/nixos/home-manager/programs/vim.nix index 39bc0961..724f521c 100644 --- a/nixos/home-manager/programs/vim.nix +++ b/nixos/home-manager/programs/vim.nix @@ -11,6 +11,7 @@ withRuby = true; plugins = with pkgs.vimPlugins; [ + ack-vim coc-highlight coc-nvim coc-rust-analyzer @@ -19,6 +20,7 @@ fzf-vim nerdtree nerdtree-git-plugin + quickfix-reflector-vim rainbow tabular vim-airline