From ebfa3190f61fd92a1ecf1171d2526ee0c791d4ff Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 12 Feb 2021 10:56:26 +0100 Subject: nvim: add CoC setup --- neovim/.config/nvim/init.vim | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'neovim/.config/nvim') diff --git a/neovim/.config/nvim/init.vim b/neovim/.config/nvim/init.vim index d58bba4..9146646 100644 --- a/neovim/.config/nvim/init.vim +++ b/neovim/.config/nvim/init.vim @@ -82,6 +82,84 @@ Plug 'fisadev/FixedTaskList.vim' " from this plugin is disabled "Plug 'davidhalter/jedi-vim' +Plug 'neoclide/coc.nvim', {'branch': 'release'} +" 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. +if has('patch8.1.1068') + " Use `complete_info` if your (Neo)Vim version supports it. + inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" +else + imap 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) +" Add `:Format` command to format current buffer. +command! -nargs=0 Format :call CocAction('format') +" 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 +" -- END COC SETUP -- + " Automatically close parenthesis, etc "Plug 'Townk/vim-autoclose' @@ -239,7 +317,9 @@ map :TaskList " file finder mapping nmap ,e :Files +" buffer search nmap ,b :Buffers +" Ag search nmap ,a :Ag " tags (symbols) in current file finder mapping nmap ,g :BTag -- cgit v1.2.3