" designed for vim 8+ (and inspired by rwxrob) " 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 set undodir="~/.vim/undodir" set undofile " map leader to Space let mapleader = " " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " ui """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" syntax enable set number set colorcolumn=79 set updatetime=50 set scrolloff=8 set smartindent set incsearch " hilight search matches while typing """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 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,TextChangedP,CmdlineEnter,CmdlineLeave,CmdlineChanged * 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\ -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 cwindow autocmd QuickFixCmdPost lgetexpr 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 :lnext map pc :lnext """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " misc keys """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " open help with word under cursor map oh :execute "help " . expand("") " move between splits with hjkl map j map k map h map 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 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " better grep wrapper " https://gist.github.com/romainl/56f0c28ef953ffc157f36cc495947ab3 " function! Grep(...) return system(join([&grepprg] + [expandcmd(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 function! PlaceSign(id, symbol, prio, line_number) call sign_define(a:symbol, {'text': a:symbol}) call sign_place(a:id, '', a:symbol, bufnr(''), {'lnum': a:line_number, 'priority': a:prio, 'text': a:symbol}) endfunction 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 lines = split(lines, "\n")[1:] for i in range(len(lines)) let line = lines[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, 99, row) endif endfor endfunction