From c62942a6fc3e2a87b4bb7158244a47538ee3f23f Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 13 Jun 2023 09:13:09 +0100 Subject: [PATCH] Update mappings and install CoC --- init.vim | 238 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 210 insertions(+), 28 deletions(-) diff --git a/init.vim b/init.vim index 0acfe76..eaba6e1 100644 --- a/init.vim +++ b/init.vim @@ -26,6 +26,11 @@ Plug 'godlygeek/tabular' " Easy alligning of code based on match, :Tab/| will li Plug 'plasticboy/vim-markdown' " All markdown features (some are disabled by polyglot) Plug 'sheerun/vim-polyglot' " Dynamically loads syntax hilighting from multiple packages Plug 'ms-jpq/chadtree', { 'branch': 'chad', 'do': 'python3 -m chadtree deps' } " A file tree +Plug 'wakatime/vim-wakatime' +Plug 'neoclide/coc.nvim', { 'branch': 'release' } " Autocompletion +Plug 'github/copilot.vim' " Copilot +Plug 'easymotion/vim-easymotion' " Advanced navigation +Plug 'antoinemadec/coc-fzf' " Open CocList results in fzf "Plug 'phpactor/phpactor', { 'do': 'composer install', 'for': 'php' } "Plug 'ncm2/ncm2' @@ -63,7 +68,9 @@ set undofile "Store the undo history "set spell "Enable spell checking set autowriteall "Save the file when switching buffers set colorcolumn=80,120 -"}}} +set updatetime=300 " Recommended by COC +set signcolumn=yes " Also recommended by COC +" }}} " Visuals ---- {{{ if isdirectory(system('echo -n "${XDG_CACHE_HOME:-$HOME/.cache}/wal"')) @@ -88,27 +95,28 @@ hi LineNr guibg=bg hi vertsplit guifg=bg guibg=bg " }}} -" Split Management --- {{{ +" Navigation --- {{{ set splitbelow set splitright -"We'll set simpler mappings to switch between splits -"Decrease window size (replaces some weird netrw stuff) -nnoremap - -"Increase window size (Redraws the screen, use :redraw instead) -nnoremap + -nnoremap -nnoremap -nnoremap -nnoremap -"Decrease window size (Backspace clone) -inoremap - -"Increase window size (Replaces leaving `insertmode`, don't use `insertmode`) -inoremap + -inoremap i -inoremap i -inoremap i -inoremap i +"Increase/Decrease window size +nnoremap < +nnoremap > +nnoremap + +nnoremap - +"Move around splits +nnoremap +nnoremap +nnoremap +nnoremap +"Go to next tab +nnoremap :tabnext +nnoremap :tabprev +nnoremap :vertical resize:resize +nnoremap = +nnoremap :vsplit +nnoremap :split +nnoremap :q " }}} " Search --- {{{ @@ -128,9 +136,9 @@ nnoremap es :source $MYVIMRC "Changing unused ctrl bindings "Turn on git blame -nnoremap Git blame +nnoremap Git blame "List all tags in the current buffer (replaced pageup, use CTRL-u instead) -nnoremap BTags +nnoremap CocFzfList outline "List all tags in directory "nnoremap Tags "List all the recently opened files (replaced scroll one line up, use "k") @@ -152,7 +160,7 @@ nnoremap GFiles "Search all files in directory nnoremap Files "Toggle file draw -nnoremap CHADopen +nnoremap CHADopen "Search all snippets (uses ultisnips) nnoremap Snippets "Search git history (replaced scroll one line up, use "k") @@ -161,11 +169,11 @@ nnoremap Commits nnoremap BCommits "Turn on git blame -inoremap GBlame +inoremap Git blame "List all tags in the current buffer -inoremap BTags +inoremap BTags "List all tags in directory -inoremap Tags +inoremap Tags "List all the recently opened files (replaced inserting characters from below) inoremap History "Search within the current buffer @@ -187,7 +195,7 @@ inoremap GFiles "Search all files in directory inoremap Files "Toggle file draw (replaces CTRL-v clone) -nnoremap CHADopen +inoremap CHADopen "Search all snippets (uses ultisnips) inoremap Snippets "Search git history (replaced inserting characters from above) @@ -243,7 +251,156 @@ command! X execute 'silent! x !doas /usr/bin/tee % >/dev/null' edit! " }}} " Plugins --- {{{ - + +" COC --- {{{ +" 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 + +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) + +" Formatting selected code +xmap f (coc-format-selected) +nmap f (coc-format-selected) + +augroup mygroup + autocmd! + " Setup formatexpr specified filetype(s) + autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') + " Update signature help on jump placeholder + autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') +augroup end + +" Applying code actions to the selected code block +" Example: `aap` for current paragraph +xmap a (coc-codeaction-selected) +nmap a (coc-codeaction-selected) + +" Remap keys for applying code actions at the cursor position +nmap ac (coc-codeaction-cursor) +" Remap keys for apply code actions affect whole buffer +nmap as (coc-codeaction-source) +" Apply the most preferred quickfix action to fix diagnostic on the current line +nmap qf (coc-fix-current) + +" Remap keys for applying refactor code actions +nmap re (coc-codeaction-refactor) +xmap r (coc-codeaction-refactor-selected) +nmap r (coc-codeaction-refactor-selected) + +" Run the Code Lens action on the current line +nmap cl (coc-codelens-action) + +" Map function and class text objects +" NOTE: Requires 'textDocument.documentSymbol' support from the language server +xmap if (coc-funcobj-i) +omap if (coc-funcobj-i) +xmap af (coc-funcobj-a) +omap af (coc-funcobj-a) +xmap ic (coc-classobj-i) +omap ic (coc-classobj-i) +xmap ac (coc-classobj-a) +omap ac (coc-classobj-a) + +" Remap and to scroll float windows/popups +" if has('nvim-0.4.0') || has('patch-8.2.0750') +" nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" +" nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" +" inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" +" inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" +" vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" +" vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" +" endif + +" Use CTRL-S for selections ranges +" Requires 'textDocument/selectionRange' support of language server +nmap (coc-range-select) +xmap (coc-range-select) + +" Add `:Format` command to format current buffer +command! -nargs=0 Format :call CocActionAsync('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 CocActionAsync('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 for 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 + +" }}} + +" Emmet --- {{{ " Toggle emmet completion using with em let g:emmet_completion = 0 function ToggleEmmet() @@ -260,13 +417,19 @@ function ToggleEmmet() endif endfunction nnoremap em :call ToggleEmmet() +" }}} +" Markdown --- {{{ " Conceal markdown text set conceallevel=3 +" }}} -let g:AutoPairsFlyMode = 1 +" AutoPairs --- {{{ +let g:AutoPairsFlyMode = 0 let g:AutoPairsShortcutBackInsert = '' " Use to insert the closing parentheses if it jumped ahead by mistake +" }}} +" CHADTree --- {{{ let g:chadtree_settings = { \ 'theme': { \ 'icon_glyph_set': 'devicons', @@ -292,7 +455,9 @@ let g:chadtree_settings = { \ } \ } \ } +" }}} +" Commentary --- {{{ " function s:set_commentary_format() " echo "running command" " if &filetype =~ 'vue\|html\|svelte' @@ -310,6 +475,23 @@ let g:chadtree_settings = { " nnoremap gcc :call set_commentary_format()Commentary " nnoremap cgc :call set_commentary_format()Commentary " nnoremap cgu :call set_commentary_format()CommentaryCommentary +" }}} + +" Easymotion --- {{{ +let g:EasyMotion_do_mapping = 0 " Disable default mappings + +map (easymotion-prefix) +" Jump to anywhere you want with minimal keystrokes, with just one key binding. +" `s{char}{label} +nmap s (easymotion-overwin-f) + +" Turn on case-insensitive feature +let g:EasyMotion_smartcase = 1 + +" JK motions: Line motions +map j (easymotion-j) +map k (easymotion-k) +" }}} " }}}