" VIMRC " Basics {{{ filetype plugin indent on " Add filetype, plugin, and indent support syntax on " Turn on syntax highlighting "}}} " Variable Assignments {{{ let $MYVIMRC="~/.vimrc" let $MYVIMDIR="~/.vim" " }}} " Settings {{{ set shell=/usr/bin/zsh " Prefer zsh for shell-related tasks set grepprg=LC_ALL=C\ grep\ -rns " Faster ASCII-based grep set expandtab " Prefer spaces over tabs set hidden " Prefer hiding over unloading buffers set wildcharm= " Macro-compatible command-line wildchar set path=.,,** " Search relative to current file + directory set noswapfile " No swapfiles period. set tags=./tags;,tags; " ID Tags relative to current file + directory set shiftwidth=2 " Indentation defaults (<< / >> / == / auto) set shiftround " Snap indents via > or < to multiples of sw " }}} " Mappings {{{ " Self-explanatory convenience mappings noremap jj noremap noremap $ inoremap O inoremap nnoremap ' ` vnoremap ; : vnoremap : ; nnoremap ; : nnoremap : ; " Re-detect filetype nnoremap t :filetype detect " Visually select pasted or yanked text nnoremap gV `[v`] " Toggle Paste mode nnoremap p :set paste! " Fast switching to the alternate file nnoremap :buffer# " Faster buffer navigation nnoremap ,b :buffer * " Black hole deletes nnoremap d "_d " Command-line like forward-search cnoremap " Command-line like reverse-search cnoremap " Often utilize vertical splits cnoreabbrev v vert " Quit out of ex-mode faster cnoreabbrev vv visual " Fast global commands nnoremap ,g :g//# " Faster project-based editing nnoremap ,e :e **/* " Join yanked text on a yank (needed for terminal mode copies) vnoremap yy y:let @"=substitute(@", '\n', '', 'g'):call yank#Osc52Yank() " Capture ex-command output to default register nnoremap ,p :let @"=substitute(execute('pwd'), '\n', '', 'g') " Reload snippet configuration files nnoremap :call UltiSnips#RefreshSnippets() " Make the directory for which the current file should be in nnoremap ,m :!mkdir -p %:h " Bindings for more efficient path-based file navigation nnoremap ,f :find * nnoremap ,v :vert sfind * nnoremap ,F :find =fnameescape(expand('%:p:h')).'/**/*' nnoremap ,V :vert sfind =fnameescape(expand('%:p:h')).'/**/*' " Argslist navigation nnoremap [a :previous nnoremap ]a :next nnoremap [A :first nnoremap ]A :last " More manageable brace expansions inoremap (; ();O inoremap (, (),O inoremap {; {};O inoremap {, {},O inoremap [; [];O inoremap [, [],O " Useful for accessing commonly-used files nnoremap v :e $MYVIMRC nnoremap f :e ='$MYVIMDIR/ftplugin/'.&filetype.'.vim' nnoremap i :e ='$MYVIMDIR/indent/'.&filetype.'.vim' nnoremap z :e ~/.zshrc nnoremap s :UltiSnipsEdit " Window management nnoremap + :exe "resize " . (winheight(0) * 6/5) nnoremap - :exe "resize " . (winheight(0) * 5/6) " Access file name data cnoremap \fp =expand("%:p:h") inoremap \fp =expand("%:p:h") cnoremap \fn =expand("%:t:r") inoremap \fn =expand("%:t:r") " Symbol-based navigation nnoremap ,t :tjump / nnoremap ,d :dlist / nnoremap ,i :ilist / " Kill bad habits noremap h noremap j noremap k noremap l inoremap " Scratch Buffer command! SC vnew | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile " External Grep command! -nargs=+ -complete=file_in_path -bar Grep sil! grep! | redraw! " Custom function aliases nnoremap ,G :Grep cnoremap cmdline#AutoComplete() " }}} " {{{ Autocommands " Automatically call OSC52 function on yank to sync register with host clipboard " augroup Yank " autocmd! " autocmd TextYankPost * if v:event.operator ==# 'y' | call yank#Osc52Yank() | endif " augroup END " Create file-marks for commonly edited file types augroup FileMarks autocmd! autocmd BufLeave *.html normal! mH autocmd BufLeave *.snippets normal! mS autocmd BufLeave *.js normal! mJ autocmd BufLeave *.ts normal! mT autocmd BufLeave *.vim normal! mV autocmd BufLeave *.bzl normal! mB augroup END " }}} " Neovim {{{ if has("nvim") " Terminal mode: tnoremap autocmd TermOpen * startinsert " Prefer h-j-k-l mode-agnostic means of switching windows tnoremap h tnoremap j tnoremap k tnoremap l inoremap h inoremap j inoremap k inoremap l vnoremap h vnoremap j vnoremap k vnoremap l nnoremap h nnoremap j nnoremap k nnoremap l " nr2char({expr}) returns string with value {expr} " Equivalent to "[reg]pi: paste the contents of [reg] tnoremap '"'.nr2char(getchar()).'pi' endif " }}} " Snippets {{{ let g:UltiSnipsSnippetDirectories=["UltiSnips"] let g:UltiSnipsExpandTrigger = "" let g:UltiSnipsJumpForwardTrigger = "" let g:UltiSnipsJumpBackwardTrigger = "" " Use carriage returns as a surround character let g:surround_13 = "\n\t\r\n" " Sometimes UltiSnips does not auto reload snippets cnoreabbrev resnip call UltiSnips#RefreshSnippets() " }}}