" designed for vim 7+ (and inspired by rwxrob) " tested with vim 7.4.629 " https://github.com/starr-dusT/dotfiles """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " general """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set autowrite " automatically write files on close " tabs and spaces and stuff set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab " undos if !isdirectory($HOME."/.vim") call mkdir($HOME."/.vim", "", 0770) endif if !isdirectory($HOME."/.vim/undo-dir") call mkdir($HOME."/.vim/undo-dir", "", 0700) endif set undodir=~/.vim/undo-dir set undofile " map leader to Space let mapleader = " " " clipboard set clipboard=unnamedplus set clipboard+=unnamed """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " ui """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" syntax enable set number set colorcolumn=79 set updatetime=50 set scrolloff=8 set smartindent set incsearch " hilight search matches while typing " maximize focused split vertically creating almost 'tabs' let g:max_lock=0 autocmd WinEnter * if !g:max_lock | call MaxSplit(&buftype) | endif """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " wildmenu """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " ignore compiled files set wildignore=*.o,*~,*.pyc if has("win16") || has("win32") set wildignore+=.git\*,.hg\*,.svn\* else set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store endif " enable fuzzy finding in the vim command line set path=$PWD/** set nowildmenu set wildmode=list:full """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " netrw """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let g:netrw_banner = 0 " disable dumb banner " use l and h for up/down dir augroup netrw_setup | au! au FileType netrw nmap l au FileType netrw nmap h - augroup END map e :Ex " open explorer """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " marks """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " automatically update marks with helper function au CursorHold,CursorHoldI,CursorMoved,CursorMovedI,TextChanged * silent! call UpdateMarkSigns() " allow only global marks noremap ' "'".toupper(nr2char(getchar())) noremap m "m".toupper(nr2char(getchar())) sunmap ' sunmap m " list marks map mm :marks " clear marks map md :delmarks A-Z0-9 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " grep """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set grepprg=grep\ --exclude-dir=\".git\"\ -snH\ $* " use system grep command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep() command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep() " open quickfix augroup quickfix autocmd! autocmd QuickFixCmdPost cgetexpr bot cwindow autocmd QuickFixCmdPost lgetexpr bot lwindow augroup END " grep into quickfix/location list map fq :Grep -r map fl :LGrep -r " next/last location map nl :lnext map pl :lprev " next/last quickfix map nc :cnext map pc :cnext """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " misc keys """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " yank and paste from system clipboard map y :"+y map p :"+p p " open help with word under cursor map oh :execute "help " . expand("") " move between splits with hjkl map j j map k k map h h map l l " find map ff :find * " change directories map cc :cd map cd :cd ~/.local/share/chezmoi " open common files map ov :e ~/.local/share/chezmoi/home/dot_vimrc " functions keys map :set number! :set relativenumber! map :set list! map :set cursorline! map :set spell! " better use of arrow keys, number increment/decrement nnoremap nnoremap """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " helpers """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " maximize current vertical split (and handle quick/location list) " OG baby! " function! MaxSplit(b) let g:max_lock=1 " prevent multiple autocmds at the same time let curr_win = winnr() if a:b !=# 'quickfix' && a:b !=# 'locationlist' exe "normal! z99\" for i in range(winnr(), winnr('$')) let b = getwinvar(i, '&buftype') if b == 'quickfix' || b == 'locationlist' exe "normal! z10\" endif wincmd j endfor exe curr_win . "wincmd w" endif let g:max_lock=0 endfunction " better grep wrapper " https://gist.github.com/romainl/56f0c28ef953ffc157f36cc495947ab3 " function! Grep(...) return system(join([&grepprg] + [expand(join(a:000, ' '))], ' ')) endfunction " Check if file is valid and exists " ChatGippity " function! IsValidFilename(filename) let expanded_filename = expand(a:filename) if !empty(expanded_filename) && filereadable(expanded_filename) return 1 else return 0 endif endfunction " Place sign with particular symbol at line " ChatGippity " function! PlaceSign(id, symbol, line_number) let buff = bufnr('') " For compatibility with vim7 can't use nice sign functions exe "sign define " . a:symbol . " text=" . a:symbol exe "sign place " . a:id . " line=" . a:line_number . " name=" . a:symbol . " buffer=" . buff endfunction " Use signs to visualize marks and update for current buffer " OG baby! " function! UpdateMarkSigns() " Reserved unique IDs for marks in case we want to remove in future " without wiping out all signs let resvIDs = range(1000, 1027) " wipe out all signs (might improve in future) execute "sign unplace *" " get all marks let lines = "" redir => lines :silent marks redir END let linesList = split(lines, "\n")[1:] for i in range(len(linesList)) let line = linesList[i] let id = resvIDs[i] let splitLine = split(line) let name = splitLine[0] let row = splitLine[1] let col = splitLine[2] try " empty lines at marks will break things let file = splitLine[3] catch let file = "" endtry " If marks is in another file we don't need to display it if !IsValidFilename(file) call PlaceSign(id, name, row) endif endfor endfunction