浏览代码

chore: switch to CoC, some other things

Sam Jaffe 9 月之前
父节点
当前提交
ca844c1cf6
共有 1 个文件被更改,包括 207 次插入42 次删除
  1. 207 42
      vimrc

+ 207 - 42
vimrc

@@ -1,7 +1,6 @@
 " wreed vimrc
 " vim:foldmethod=marker:foldlevel=0:
 
-let g:python3_host_skip_check = 1
 
 "{{{ ***** PLUGINS INSTALLATION ***** "
 
@@ -11,9 +10,13 @@ call plug#begin('~/.vim/bundle')
 
 " ***** plugins that require more stuff (compilation)
 " As-you-type semantic completion. 
-Plug 'Valloric/YouCompleteMe', { 'frozen': 0, 'for': ['cpp', 'c', 'java', 'python', 'xonsh', 'sh'], 'on': ['YcmCompleter', 'YcmDiags', 'YcmForceCompileAndDiagnostics']}
-autocmd! User YouCompleteMe if !has('vim_starting') | call youcompleteme#Enable() | endif
+" Plug 'Valloric/YouCompleteMe', { 'frozen': 0, 'for': ['cpp', 'c', 'java', 'python', 'xonsh', 'sh'], 'on': ['YcmCompleter', 'YcmDiags', 'YcmForceCompileAndDiagnostics']}
+" autocmd! User YouCompleteMe if !has('vim_starting') | call youcompleteme#Enable() | endif
 
+" Use release branch (recommend)
+Plug 'neoclide/coc.nvim', {'branch': 'release'}
+Plug 'clangd/coc-clangd'
+Plug 'mfussenegger/nvim-lint'
 
 " ***** simple plugins
 " easy buffer management. Replaced by Unite
@@ -38,7 +41,7 @@ Plug 'mkitt/tabline.vim'
 " shows an outline of all Tags in a file 
 Plug 'majutsushi/tagbar'
 " Snippet completion
-Plug 'SirVer/ultisnips' ", { 'on': []}
+" Plug 'SirVer/ultisnips' ", { 'on': []}
 " Make vim priiiiity
 Plug 'bling/vim-airline'
 Plug 'vim-airline/vim-airline-themes'
@@ -266,50 +269,203 @@ endif
 " {{{##### YouCompleteMe #####
 " Do not open preview window when completing
 set completeopt=menuone
-let g:ycm_add_preview_to_completeopt = 0
-" Auto Close preview window
-let g:ycm_autoclose_preview_window_after_insertion = 1
-" Disable Tab for cycling through commands so that UtilSnips will still work
-let g:ycm_key_list_select_completion=['<Down>']
-let g:ycm_key_list_previous_completion=['<Up>']
-let g:ycm_collect_identifiers_from_tags_files=0
-let g:ycm_collect_identifiers_from_comments_and_strings = 0
-let g:ycm_complete_in_comments = 1
-let g:ycm_key_invoke_completion = '<C-N>'
-" let g:ycm_path_to_python_interpreter = '/opt/local/bin'
-"let g:ycm_extra_conf_globlist = ['~/.ycm_extra_conf.py']
-let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
-let g:ycm_use_ultisnips_completer = 1
-let g:ycm_filetype_blacklist = {
-            \ 'tagbar' : 1,
-            \ 'nerdtree': 1,
-            \ 'qf' : 1,
-            \ 'notes' : 1,
-            \ 'markdown' : 1,
-            \ 'unite' : 1,
-            \ 'vimwiki' : 1,
-            \ 'pandoc' : 1,
-            \ 'infolog' : 1,
-            \ 'mail' : 1
-            \}
+"let g:ycm_add_preview_to_completeopt = 0
+"" Auto Close preview window
+"let g:ycm_autoclose_preview_window_after_insertion = 1
+"" Disable Tab for cycling through commands so that UtilSnips will still work
+"let g:ycm_key_list_select_completion=['<Down>']
+"let g:ycm_key_list_previous_completion=['<Up>']
+"let g:ycm_collect_identifiers_from_tags_files=0
+"let g:ycm_collect_identifiers_from_comments_and_strings = 0
+"let g:ycm_complete_in_comments = 1
+"let g:ycm_key_invoke_completion = '<C-N>'
+"" let g:ycm_path_to_python_interpreter = '/opt/local/bin'
+""let g:ycm_extra_conf_globlist = ['~/.ycm_extra_conf.py']
+"let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
+"let g:ycm_use_ultisnips_completer = 1
+"let g:ycm_filetype_blacklist = {
+"            \ 'tagbar' : 1,
+"            \ 'nerdtree': 1,
+"            \ 'qf' : 1,
+"            \ 'notes' : 1,
+"            \ 'markdown' : 1,
+"            \ 'unite' : 1,
+"            \ 'vimwiki' : 1,
+"            \ 'pandoc' : 1,
+"            \ 'infolog' : 1,
+"            \ 'mail' : 1
+"            \}
 
 " Python3 completion by default
 " let g:ycm_python_binary_path = system('readlink -f ' . system('which python3'))
-let g:ycm_python_binary_path = 'python3'
+" let g:ycm_python_binary_path = '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3'
+let g:python_host_prog = '/Users/samjaffe/.pyenv/versions/2.7/bin/python'
+let g:python3_host_prog = '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3'
 
 " Mappings
-nnoremap <leader>] :YcmCompleter GoTo<CR>
-nnoremap <leader>[ :YcmCompleter GoToReferences<CR>
-nnoremap <leader>gt :YcmCompleter GetType<CR>
-nnoremap <leader>gp :YcmCompleter GetParent<CR>
-nnoremap <leader>gd :YcmCompleter GetDoc<CR>
-nnoremap <leader>= :YcmCompleter FixIt<CR>
+" nnoremap <leader>] :YcmCompleter GoTo<CR>
+" nnoremap <leader>[ :YcmCompleter GoToReferences<CR>
+" nnoremap <leader>gt :YcmCompleter GetType<CR>
+" nnoremap <leader>gp :YcmCompleter GetParent<CR>
+" nnoremap <leader>gd :YcmCompleter GetDoc<CR>
+" nnoremap <leader>= :YcmCompleter FixIt<CR>
 
-nnoremap <F1> :YcmDiags<CR>:map <buffer> q cl<CR>
-nnoremap <leader><F1> :YcmForceCompileAndDiagnostics<CR>
+" nnoremap <F1> :YcmDiags<CR>:map <buffer> q cl<CR>
+" nnoremap <leader><F1> :YcmForceCompileAndDiagnostics<CR>
 
 
 " }}}
+" {{{##### coc.nvim #####
+" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
+" delays and poor user experience
+set updatetime=300
+
+" 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: 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 <tab>' to make sure tab is not mapped by
+" other plugin before putting this into your config
+inoremap <silent><expr> <TAB>
+      \ coc#pum#visible() ? coc#pum#next(1) :
+      \ CheckBackspace() ? "\<Tab>" :
+      \ coc#refresh()
+inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
+
+" Make <CR> to accept selected completion item or notify coc.nvim to format
+" <C-g>u breaks current undo, please make your own choice
+inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
+                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
+
+function! CheckBackspace() abort
+  let col = col('.') - 1
+  return !col || getline('.')[col - 1]  =~# '\s'
+endfunction
+
+" Use <c-space> to trigger completion
+if has('nvim')
+  inoremap <silent><expr> <c-space> coc#refresh()
+else
+  inoremap <silent><expr> <c-@> coc#refresh()
+endif
+
+" Use `[g` and `]g` to navigate diagnostics
+" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
+nmap <silent> [g <Plug>(coc-diagnostic-prev)
+nmap <silent> ]g <Plug>(coc-diagnostic-next)
+
+" GoTo code navigation
+nmap <silent> gd <Plug>(coc-definition)
+nmap <silent> gy <Plug>(coc-type-definition)
+nmap <silent> gi <Plug>(coc-implementation)
+nmap <silent> gr <Plug>(coc-references)
+
+" Use K to show documentation in preview window
+nnoremap <silent> K :call ShowDocumentation()<CR>
+
+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 <leader>rn <Plug>(coc-rename)
+
+" Formatting selected code
+xmap <leader>f  <Plug>(coc-format-selected)
+nmap <leader>f  <Plug>(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: `<leader>aap` for current paragraph
+xmap <leader>a  <Plug>(coc-codeaction-selected)
+nmap <leader>a  <Plug>(coc-codeaction-selected)
+
+" Remap keys for applying code actions at the cursor position
+nmap <leader>ac  <Plug>(coc-codeaction-cursor)
+" Remap keys for apply code actions affect whole buffer
+nmap <leader>as  <Plug>(coc-codeaction-source)
+" Apply the most preferred quickfix action to fix diagnostic on the current line
+nmap <leader>qf  <Plug>(coc-fix-current)
+
+" Remap keys for applying refactor code actions
+nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
+xmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
+nmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
+
+" Run the Code Lens action on the current line
+nmap <leader>cl  <Plug>(coc-codelens-action)
+
+" Map function and class text objects
+" NOTE: Requires 'textDocument.documentSymbol' support from the language server
+xmap if <Plug>(coc-funcobj-i)
+omap if <Plug>(coc-funcobj-i)
+xmap af <Plug>(coc-funcobj-a)
+omap af <Plug>(coc-funcobj-a)
+xmap ic <Plug>(coc-classobj-i)
+omap ic <Plug>(coc-classobj-i)
+xmap ac <Plug>(coc-classobj-a)
+omap ac <Plug>(coc-classobj-a)
+
+" Use CTRL-S for selections ranges
+" Requires 'textDocument/selectionRange' support of language server
+nmap <silent> <C-s> <Plug>(coc-range-select)
+xmap <silent> <C-s> <Plug>(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', <f-args>)
+
+" 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 <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
+" Manage extensions
+nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
+" Show commands
+nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
+" Find symbol of current document
+nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
+" Search workspace symbols
+nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
+" Do default action for next item
+nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
+" Do default action for previous item
+nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
+" Resume latest coc list
+nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>
+" }}}
+
+" {{{##### Linters #####
+lua require('lint').linters_by_ft = { python = {'mypy'} }
+command! -nargs=* Lint lua require('lint').try_lint(<f-args>)
+au BufWritePost,BufRead * Lint
+" }}}
+
 " {{{##### Multiple Cursors #####
 let g:multi_cursor_exit_from_insert_mode = 0
 
@@ -359,6 +515,14 @@ let g:mundo_preview_bottom = 1
 " }}}
 " {{{##### EasyAlign #####
 vmap <Enter> <Plug>(LiveEasyAlign)
+let g:easy_align_delimiters = {
+\ '\': {
+\     'pattern':         '\\' },
+\ '/': {
+\     'pattern':         '//\+\|/\*\|\*/',
+\     'delimiter_align': 'l',
+\     'ignore_groups':   ['!Comment'] },
+\ }
 
 " }}}
 " {{{##### DelimitMate #####
@@ -522,6 +686,7 @@ set background=dark
 syntax on
 
 colorscheme devbox-dark-256
+set termguicolors&
 
 set showcmd
 "}}}
@@ -576,7 +741,7 @@ nnoremap <leader>O O<ESC>
 nnoremap <leader>c cc<ESC>
 
 " Exit insert mode and put ';' at the end of the line
-inoremap ;<Esc> <Esc>A;<Esc>
+inoremap ;; <Esc>A;<Esc>
 
 " Open tag in new tab
 nnoremap <M-]> <C-W><C-]><C-W>T
@@ -630,7 +795,7 @@ vnoremap <silent> # :call VisualSelection('b')<CR>
 let g:run_command = 'echo No run command defined'
 autocmd FileType lilypond setlocal makeprg=lilypond
 autocmd FileType python setlocal makeprg=mypy
-nnoremap <F3> :Make %<CR>
+nnoremap <F3> :Make<CR>
 nnoremap <leader>` :execute "Start " . g:run_command<CR>
 
 " Quickly edit a macro
@@ -646,7 +811,7 @@ nnoremap <M-C-O> <C-o>:bd! #<CR>
 
 "{{{ ***** COMMANDS ***** " 
 " make todo list
-command! -nargs=* -complete=file Todos execute "Unite -keep-focus -auto-resize -no-quit -buffer-name=Todos vimgrep:*:TODO(" . expand("$USER") . ")"
+command! -nargs=* -complete=file Todos execute "Unite -keep-focus -auto-resize -no-quit -buffer-name=Todos vimgrep:%:TODO(" . expand("$USER") . ")"
 
 "Wrapper for make sequence
 "replaced by vim-dispatch plugin