Skip to content

Instantly share code, notes, and snippets.

@schulace
Last active August 31, 2022 19:21
Show Gist options
  • Select an option

  • Save schulace/39ffd58ca0ac57735e5b06f1c0d09887 to your computer and use it in GitHub Desktop.

Select an option

Save schulace/39ffd58ca0ac57735e5b06f1c0d09887 to your computer and use it in GitHub Desktop.
call plug#begin('~/.vim/plugged')
" file-browser inside of Vim
Plug 'scrooloose/nerdtree'
" fuzzy file find
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.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'}
" status line
Plug 'vim-airline/vim-airline'
" tags in bar
Plug 'majutsushi/tagbar'
" Plug 'junegunn/rainbow_parentheses.vim'
" show function / scope context
Plug 'wellle/context.vim'
" Allow surrounding
Plug 'tpope/vim-surround'
" rust highlighting
" Plug 'arzg/vim-rust-syntax-ext'
" auto light and dark mode
Plug 'vimpostor/vim-lumen'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
call plug#end()
"copy to clipboard by default when yanking
set clipboard=unnamedplus
filetype plugin on
syntax enable
" yank path to clipboard
nmap <silent> cp :let @+ = expand("%")<CR>
set shell=/bin/zsh
set ignorecase
set smartcase
set expandtab
set shiftwidth=2
autocmd BufWritePre *.rs,*.js,*.ts,*.jsx,*.tsx,*.py Format
let g:airline#extensions#tagbar#flags = 'f' " show full tag hierarchy
" make window resizing less painful
map <C-w>, <C-w>10<
map <C-w>. <C-w>10>
set number
set relativenumber
set mouse=a
" set up theme
if (has("nvim"))
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
if (has("termguicolors"))
set termguicolors
endif
let g:one_allow_italics = 1
let g:airline_theme='one'
colo one
set cmdheight=1
" don't show bottom line that says `--Insert` since lightline takes care of it
set noshowmode
" fzf config
" Override git log to show authors
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h %C(red)%aN%Creset: %s%d %C(bold)%cr"'
" make Rg command not include filename in search
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1,
\ fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}), <bang>0)
" note that this will break if you don't have `bat` installed on your machine
let $FZF_DEFAULT_OPTS="--preview-window 'right:57%' --preview 'bat --line-range :300 {}'
\ --bind ctrl-y:preview-up,ctrl-e:preview-down,
\ctrl-b:preview-page-up,ctrl-f:preview-page-down,
\ctrl-u:preview-half-page-up,ctrl-d:preview-half-page-down,
\shift-up:preview-top,shift-down:preview-bottom,
\alt-up:half-page-up,alt-down:half-page-down"
command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}, 'up:80%', 'ctrl-/'), <bang>0)
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } }
" let g:fzf_preview_window = ['up:40%', 'ctrl-/']
map <silent> <Leader>p :GFiles<CR>
map <silent> <Leader>gg :GFiles?<CR>
map <silent> <Leader>b :Buffers<CR>
" use ripgrep over grip for builtin search
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
" misc
map <silent> <C-h> :noh<CR>
map <silent> <Leader>t :TagbarToggle<CR>
map <silent> <Leader>F :NERDTreeFind<CR>
map <silent> <C-n> :NERDTreeToggle<CR>
map <silent> <Leader>sg :Git<CR><C-w>H:vertical resize 70<CR>
" BEGIN COC CONFIG
" ################
"
let g:coc_node_path = '/Users/alexschuler/.nvm/versions/node/v14.18.1/bin/node'
let g:coc_global_extensions = ['coc-tabnine', 'coc-eslint', 'coc-tsserver', 'coc-prettier', 'coc-stylelint', 'coc-rust-analyzer', 'coc-julia', 'coc-json']
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" 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>
" end COC DEFAULTS
" begin my coc stuff
nmap <silent> gs :sp<CR><Plug>(coc-definition)
nmap <silent> gS :vsp<CR><Plug>(coc-definition)
autocmd FileType rust nnoremap <silent><nowait> <space>d :<C-u>CocCommand rust-analyzer.openDocs<CR>
autocmd FileType rust nmap <silent> <Leader>tt :CocCommand rust-analyzer.run<CR>
:tnoremap <Esc> <C-\><C-n>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment