From 1cadbbcf643dc9bf9c2c5ceecc7afcb3f951287e Mon Sep 17 00:00:00 2001 From: Dmitry Chumak Date: Fri, 2 Sep 2022 20:13:33 +0300 Subject: [PATCH] [vim] coc-nvim plugin added, plus pyright extension --- vim/coc.vim | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vim/vimrc | 18 +++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 vim/coc.vim diff --git a/vim/coc.vim b/vim/coc.vim new file mode 100644 index 0000000..53b64ee --- /dev/null +++ b/vim/coc.vim @@ -0,0 +1,56 @@ +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 c coc#refresh() +" endif + +" 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 + +" 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) + +"set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} + +" 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 buffer. +nmap ac (coc-codeaction) +" Apply AutoFix to problem on the current line. +nmap qf (coc-fix-current) diff --git a/vim/vimrc b/vim/vimrc index f88d623..55a3e5a 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -8,6 +8,9 @@ filetype plugin indent on "Включает определение типа фа set encoding=utf-8 syntax enable set timeoutlen=300 ttimeoutlen=0 " https://www.johnhawthorn.com/2012/09/vi-escape-delays/ +" For coc-vim. Always show the signcolumn, otherwise it would shift the text each time +" diagnostics appear/become resolved. +set signcolumn=yes set number relativenumber set backspace=indent,eol,start filetype plugin indent on @@ -32,6 +35,7 @@ call plug#begin('~/.vim/bundle') "Начать искать плагины в э Plug 'towolf/vim-helm' Plug 'pearofducks/ansible-vim' + Plug 'neoclide/coc.nvim', {'branch': 'release'} call plug#end() "Перестать это делать " @@ -138,6 +142,20 @@ let g:ansible_extra_keywords_highlight = 1 let g:ansible_name_highlight = 'b' let g:ansible_yamlKeyName = 'yamlKey' +" +" CoC plugin settings +" +let g:coc_global_extensions = ['coc-pyright'] +source ~/.vim/coc.vim +function! s:enable_coc_for_type() + let l:filesuffix_whitelist = ['py'] + if index(l:filesuffix_whitelist, expand('%:e')) == -1 + let b:coc_enabled = 0 + endif +endfunction +autocmd BufRead,BufNewFile * call s:enable_coc_for_type() + + " YAML files config autocmd FileType yaml,yml setlocal ts=2 sts=2 sw=2 expandtab let g:indentLine_char = '⦙'