From b61f9943ce086afb72e8446c23f53d73408181da Mon Sep 17 00:00:00 2001 From: Chad Ostrowski <221614+chadoh@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:31:29 -0500 Subject: [PATCH] update vim for CoC --- bash/bashrc | 3 + git/gitignore | 1 + vim/coc-config | 156 +++++++++++++++++++++++++++++++++++++++++++++++++ vim/vimrc | 126 +++++++++++++++++++++++---------------- 4 files changed, 235 insertions(+), 51 deletions(-) create mode 100644 vim/coc-config diff --git a/bash/bashrc b/bash/bashrc index 7574a73..68f6b96 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -108,3 +108,6 @@ ssh-add -A &> /dev/null export PATH="$HOME/.yarn/bin:$PATH" . "$HOME/.cargo/env" + +[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh +eval "$(atuin init bash)" diff --git a/git/gitignore b/git/gitignore index e5ddcfe..ed09f68 100644 --- a/git/gitignore +++ b/git/gitignore @@ -10,3 +10,4 @@ xcuserdata .vimrc .yarn-error.log .history +.zed diff --git a/vim/coc-config b/vim/coc-config new file mode 100644 index 0000000..d732016 --- /dev/null +++ b/vim/coc-config @@ -0,0 +1,156 @@ +" May need for Vim (not Neovim) since coc.nvim calculates byte offset by count +" utf-8 byte sequence +set encoding=utf-8 +" Some servers have issues with backup files, see #649 +set nobackup +set nowritebackup + +" 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 ' 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 + +" Use to trigger completion +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 i :call ShowDocumentation() + +function! ShowDocumentation() + if CocAction('hasProvider', 'hover') + call CocActionAsync('doHover') + else + call feedkeys('i', '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) + +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 f (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 diff --git a/vim/vimrc b/vim/vimrc index eabf9e9..d3c42a7 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -12,6 +12,7 @@ set pastetoggle= set showmode call plug#begin('~/.vim/plugged') +Plug 'jeffkreeftmeijer/vim-dim' Plug 'jremmen/vim-ripgrep' Plug 'scrooloose/nerdtree' Plug 'tomtom/tlib_vim' @@ -32,19 +33,17 @@ Plug 'mattn/gist-vim' let g:gist_open_browser_after_post = 1 Plug 'ecomba/vim-ruby-refactoring' Plug 'rstacruz/sparkup', {'rtp': 'vim/'} -Plug 'vim-scripts/slimv.vim' -Plug 'vim-scripts/scratch.vim' Plug 'editorconfig/editorconfig-vim' Plug 'rstacruz/vim-closer' Plug 'tpope/vim-endwise' Plug 'vim-scripts/vim-pencil' Plug 'junegunn/goyo.vim' +Plug 'junegunn/limelight.vim' +let g:limelight_conceal_ctermfg = 'gray' let g:goyo_width = '80' let g:goyo_height = '95%' -Plug 'junegunn/limelight.vim' - autocmd! User GoyoEnter Limelight autocmd! User GoyoLeave Limelight! @@ -53,13 +52,9 @@ Plug 'pangloss/vim-javascript' let g:javascript_plugin_flow = 1 Plug 'ngmy/vim-rubocop' -" Plug 'rust-lang/rust.vim' -" let g:rustfmt_autosave = 1 Plug 'cespare/vim-toml' -Plug 'chase/vim-ansible-yaml' Plug 'sbdchd/neoformat' -Plug 'elixir-editors/vim-elixir' Plug 'mhinz/vim-mix-format' let g:mix_format_on_save = 1 @@ -77,7 +72,6 @@ nmap ga (EasyAlign) " React code snippets Plug 'chadoh/vim-react-snippets' -Plug 'SirVer/ultisnips' let g:UltiSnipsExpandTrigger="" let g:UltiSnipsSnippetsDir="~/.vim/UltiSnips/" @@ -100,23 +94,8 @@ let g:user_emmet_settings = { " autocompletion & language server features with Conquer of Completion Plug 'neoclide/coc.nvim', {'branch': 'release'} -let g:coc_global_extensions = [ - \ 'coc-rls', - \ 'coc-rust-analyzer' - \] - -if isdirectory('./node_modules') && isdirectory('./node_modules/typescript') && &filetype ==# 'typescript' - let g:coc_global_extensions += ['coc-tsserver'] -endif - -if isdirectory('./node_modules') && isdirectory('./node_modules/prettier') - let g:coc_global_extensions += ['coc-prettier'] -endif - -if isdirectory('./node_modules') && isdirectory('./node_modules/eslint') - let g:coc_global_extensions += ['coc-eslint'] -endif +" Disable autocomplete in markdown files autocmd FileType markdown let b:coc_suggest_disable = 1 " TextEdit might fail if hidden is not set. @@ -136,32 +115,70 @@ set updatetime=300 " Don't pass messages to |ins-completion-menu|. set shortmess+=c -" 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. +" Remap keys for applying code actions at the cursor position +nmap f (coc-codeaction-cursor) + +" show help info, like on-hover action in VSCode +nnoremap i :call CocActionAsync('doHover') + +" Use and to navigate completion list: > + +function! CheckBackSpace() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~ '\s' +endfunction + +" Insert when previous text is space, refresh completion if not. inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : + \ coc#pum#visible() ? coc#pum#next(1): + \ CheckBackSpace() ? "\" : \ coc#refresh() -inoremap pumvisible() ? "\" : "\" +inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" -function! s:check_back_space() abort +" Use to trigger completion: > + +if has('nvim') + inoremap coc#refresh() +else + inoremap coc#refresh() +endif + +" Use to confirm completion, use: > + +inoremap coc#pum#visible() ? coc#_select_confirm() : "\" + +" To make to confirm selection of selected complete item or notify coc.nvim +" to format on enter, use: > + +inoremap coc#pum#visible() ? coc#_select_confirm() + \: "\u\\=coc#on_enter()\" + +" Map for trigger completion, completion confirm, snippet expand and jump +" like VSCode: > + +inoremap + \ coc#pum#visible() ? coc#_select_confirm() : + \ coc#expandableOrJumpable() ? + \ "\=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\" : + \ CheckBackSpace() ? "\" : + \ coc#refresh() + +function! CheckBackSpace() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction -" Use to trigger completion. -inoremap coc#refresh() +let g:coc_snippet_next = '' +" GoTo code navigation. nmap gd (coc-definition) nmap gy (coc-type-definition) +nmap gi (coc-implementation) nmap gr (coc-references) +nmap e (coc-diagnostic-next-error) -nmap e (coc-diagnostic-next) -nmap E (coc-diagnostic-prev) - -Plug 'rust-lang/rust.vim' -let g:rustfmt_autosave = 1 +" Plug 'rust-lang/rust.vim' +" let g:rustfmt_autosave = 1 Plug 'itchyny/lightline.vim' " set laststatus=2 noshowmode @@ -179,7 +196,11 @@ Plug 'tomlion/vim-solidity' " Plug 'othree/jsdoc-syntax.vim' " Plug 'maksimr/vim-jsbeautify' Plug 'leafgarland/typescript-vim' -" Plug 'codota/tabnine-vim' +Plug 'wuelnerdotexe/vim-astro' +" bug: enabling typescript causing opening process to hang for some files +" let g:astro_typescript = 'enable' +Plug 'github/copilot.vim' +Plug 'NoahTheDuke/vim-just' call plug#end() filetype plugin indent on " load file type plugins + indentation @@ -221,8 +242,8 @@ set backspace=indent,eol,start " backspace through everything in insert mode set autoindent " Show some whitespace chars -set list -set listchars=tab:▸·,trail:· +" set list +set listchars=tab:▷▷⋮,trail:· nnoremap :set wrap! linebreak! @@ -272,7 +293,8 @@ autocmd FileType gitcommit call setpos('.', [0, 1, 1, 0]) " Ctrl-P """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set wildignore+=*/tmp/**,*.scssc,*.sassc,*compiled* -let g:ctrlp_custom_ignore = '.*\(node_modules\|\/build\/\|bower_components\|dist\|res\|target\|Cargo.lock\).*' +let g:ctrlp_custom_ignore = '.*\(node_modules\|\.git\|\/build\/\|bower_components\|dist\|res\|target\|Cargo.lock\).*' +let g:ctrlp_show_hidden = 1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " MISC KEY MAPS @@ -314,21 +336,21 @@ set clipboard=unnamed """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Colors! """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -set t_Co=16 " only use 16 colors, not 256 -highlight LineNR ctermfg=238 +colorscheme dim highlight Visual term=reverse cterm=reverse ctermbg=NONE -hi Comment cterm=italic ctermfg=8 -hi EndOfBuffer ctermfg=0 -hi VertSplit ctermfg=0 -hi VertSplit ctermbg=8 -highlight Pmenu ctermbg=15 ctermfg=0 cterm=bold -highlight PmenuSel ctermbg=0 ctermfg=15 +hi Comment cterm=italic ctermfg=7 guifg=DimGrey +hi SpecialKey ctermfg=7 +" hi EndOfBuffer ctermfg=0 +hi VertSplit ctermfg=0 ctermbg=8 +" highlight Pmenu ctermbg=15 ctermfg=0 cterm=bold +" highlight PmenuSel ctermbg=0 ctermfg=15 " highlight clear SpellBad " highlight clear SpellCap " highlight SpellBad cterm=underline " highlight SpellBad ctermfg=9 " highlight SpellCap cterm=underline " highlight SpellCap ctermfg=6 +autocmd FileType json syntax match Comment +\/\/.\+$+ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Configure NERDTree @@ -403,3 +425,5 @@ set secure " improve syntax highlighting in JS/TS (adds performance cost) autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear + +nnoremap rt :RustTest