Last active
May 7, 2023 14:54
-
-
Save schulace/528eb7b91d9f1bc361922bfc86081a53 to your computer and use it in GitHub Desktop.
vimrc using CoC for language server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
call plug#begin('~/.vim/plugged') | |
" file-browser inside of Vim | |
Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] } | |
" on-demand loaded syntax highlighters for many languages | |
Plug 'sheerun/vim-polyglot' | |
" fuzzy file find | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' | |
" onedark color | |
Plug 'joshdick/onedark.vim' | |
" atome one dark/light | |
Plug 'rakr/vim-one' | |
" LaTeX support | |
Plug 'lervag/vimtex' | |
" git plugin | |
Plug 'tpope/vim-fugitive' | |
" git hunks | |
Plug 'airblade/vim-gitgutter' | |
" allows plugins that work with language servers | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
" syntax highlighting for css-in-js from styled-components | |
" Plug 'styled-components/vim-styled-components', { 'branch': 'main' } | |
" status line | |
Plug 'vim-airline/vim-airline' | |
" tags in bar | |
Plug 'majutsushi/tagbar' | |
" show function / scope context | |
" Plug 'wellle/context.vim' | |
call plug#end() | |
filetype plugin on | |
syntax enable | |
nmap cp :let @+ = expand("%")<CR> | |
set shell=/bin/zsh | |
autocmd BufWritePre *.rs,*.js,*.ts,*.jsx,*.tsx,*.py Format | |
let g:airline#extensions#tagbar#flags = 'f' " show full tag hierarchy | |
let g:coc_global_extensions = ['coc-tabnine', 'coc-eslint', 'coc-tsserver', 'coc-prettier', 'coc-stylelint', 'coc-rust-analyzer'] | |
map <silent> <C-n> :NERDTreeToggle<CR> | |
map <silent> <Leader>t :TagbarToggle<CR> | |
map <silent> <Leader>F :NERDTreeFind<CR> | |
map <silent> <Leader>p :Files<CR> | |
set number | |
set relativenumber | |
set mouse=a | |
colo one | |
" don't show bottom line that says `--Insert` since lightline takes care of it | |
set noshowmode | |
" setup COC | |
" TextEdit might fail if hidden is not set. | |
set hidden | |
" Some servers have issues with backup files, see #649. | |
set nobackup | |
set nowritebackup | |
set cmdheight=1 | |
" 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 | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Make <CR> auto-select the first completion item and notify coc.nvim to | |
" format on enter, <cr> could be remapped by other vim plugin | |
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() | |
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
" 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 <SID>show_documentation()<CR> | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
elseif (coc#rpc#ready()) | |
call CocActionAsync('doHover') | |
else | |
execute '!' . &keywordprg . " " . expand('<cword>') | |
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 codeAction to the selected region. | |
" Example: `<leader>aap` for current paragraph | |
xmap <leader>a <Plug>(coc-codeaction-selected) | |
nmap <leader>a <Plug>(coc-codeaction-selected) | |
" Remap keys for applying codeAction to the current buffer. | |
nmap <leader>ac <Plug>(coc-codeaction) | |
" Apply AutoFix to problem on the current line. | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" 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) | |
" Remap <C-f> and <C-b> for scroll float windows/popups. | |
" Note coc#float#scroll works on neovim >= 0.4.0 or vim >= 8.2.0750 | |
nnoremap <nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" | |
nnoremap <nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>" | |
inoremap <nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>" | |
inoremap <nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>" | |
vnoremap <nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#nvim_scroll(1, 1) : "\<C-f>" | |
vnoremap <nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#nvim_scroll(0, 1) : "\<C-b>" | |
" 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 CocAction('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 CocAction('runCommand', 'editor.action.organizeImport') | |
" 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> | |
nmap <silent> gs :sp<CR><Plug>(coc-definition) | |
nmap <silent> gS :vsp<CR><Plug>(coc-definition) | |
nmap <silent> <Leader>b :Buffers<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment