+set wildmode=longest:full,full " specifies how command line completion works
+set wildignorecase " ignore case when completing file names
+
+set wildignore+=.hg,.git,.svn " Version control
+set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
+set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
+set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
+set wildignore+=*.spl " compiled spelling word lists
+set wildignore+=*.sw? " Vim swap files
+set wildignore+=*.luac " Lua byte code
+set wildignore+=*.pyc " Python byte code
+set wildignore+=*.orig " Merge resolution files
+
+" running make and jumping to errors {{{2
+set makeprg=make\ -w " print changing directories
+
+set grepprg=ag\ --vimgrep\ $*
+
+" language specific {{{2
+set isfname-== " don't treat `=` as being part of filenames
+
+" various {{{2
+set virtualedit+=block " let cursor move past last char in <C-V> mode
+set virtualedit+=onemore " allow the cursor to move just past the end of the line
+set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
+
+set viewdir=$XDG_CACHE_HOME/vim/view//
+
+set sessionoptions+=unix,slash " damn windows and it's silly ways
+
+" autocmds {{{1
+" Resize splits when the window is resized {{{2
+augroup resize
+ au!
+ autocmd VimResized * :wincmd =
+augroup END
+
+" Only show cursorline in the current window and in normal mode {{{2
+augroup cline
+ au!
+ au WinLeave,InsertEnter * set nocursorline
+ au WinEnter,InsertLeave * set cursorline
+augroup END
+
+" Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
+augroup ft_stdin
+ au!
+ au StdinReadPost * :set buftype=nofile
+augroup END
+
+" Jump to last known cursor position {{{2
+augroup cursor_pos
+ au!
+ " blacklist certain filetype
+ let blacklist = ['gitcommit']
+ autocmd BufReadPost *
+ \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
+ \ exe "normal! g`\"" |
+ \ endif
+augroup END
+
+" Check for file modifications automatically {{{2
+" (current buffer only)
+" Use :NoAutoChecktime to disable it (uses b:autochecktime)
+fun! MyAutoCheckTime()
+ " only check timestamp for normal files
+ if &buftype != '' | return | endif
+ if ! exists('b:autochecktime') || b:autochecktime
+ checktime %
+ let b:autochecktime = 1
+ endif
+endfun
+augroup MyAutoChecktime
+ au!
+ au FocusGained,BufEnter,CursorHold,InsertEnter * call MyAutoCheckTime()
+augroup END
+command! NoAutoChecktime let b:autochecktime=0
+command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime
+
+augroup terminal
+ au!
+ au TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
+augroup END
+
+" bindings {{{1
+
+" allow both <space> and \ to be <leader>
+map <space> <leader>
+
+" make
+function! Make()
+ let l:make_dir = ""
+ if exists("b:make_dir")
+ let l:make_dir = "-C ".b:make_dir
+ elseif exists("g:make_dir")
+ let l:make_dir = "-C ".g:make_dir
+ endif
+
+ let l:make_targets = ""
+ if exists("g:make_targets")
+ let l:make_targets = g:make_targets
+ endif
+ execute "make! ".l:make_dir." ".l:make_targets
+endf
+nnoremap <leader>r :call Make()<cr>
+
+" unhighlight search
+nnoremap <silent> <Leader>/ :silent nohl<CR>
+
+" Tabs
+nnoremap <leader>[ :tabprev<cr>
+nnoremap <leader>] :tabnext<cr>
+
+" paste from selection
+nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
+" paste from clipboard
+nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
+
+" strip trailing whitespace
+function! StripWhitespace(line1, line2, ...) " {{{2
+ let s_report = &report
+ let &report=0
+ let pattern = a:0 ? a:1 : '\s\+$'
+ let oldview = winsaveview()
+ exe 'keepjumps keeppatterns '.a:line1.','.a:line2.'substitute/'.pattern.'//e'
+ if oldview != winsaveview()
+ redraw
+ endif
+ call winrestview(oldview)
+ let &report = s_report
+endfunction " }}}2
+command! -range=% -nargs=0 -bar Untrail keepjumps call StripWhitespace(<line1>,<line2>)
+nnoremap <silent> <leader>ww :Untrail<CR>