" make vim unusable for anyone else " from the get-go, we assume version >= 703 set nocompatible " screw vi " hacks {{{1 if has('multi_byte') scriptencoding utf-8 " allow it in this script set termencoding=utf-8 " and this terminal supports it set encoding=utf-8 " and the default file is in it endif if has("win32") " assume directory structure: " something/anything/.vimrc " this was passed to vim by the -u switch " something/vim/ " something/vim/after let $MYVIMRC=expand('') let g:rcvim=expand(':p:h:h').'/vim' else let g:rcvim=$HOME.'/.vim' endif let &backupdir=g:rcvim.'/backup' " stash tilde files elsewhere " the double slash at the end dumps the path of the file for uniqueness let &directory=g:rcvim.'/swp//' " stash swap files too let &undodir=g:rcvim.'/undo/' " undo files are cool try | call mkdir(&backupdir, "p") | catch /E739/ | endtry try | call mkdir(&directory, "p") | catch /E739/ | endtry try | call mkdir(&undodir, "p") | catch /E739/ | endtry " force colors on anything that looks reasonable if (&term =~ "^xterm") || (&term == "screen") let &t_Co=256 "let &t_AF="\e[38;5;%dm" "let &t_AB="\e[48;5;%dm" endif " main config {{{1 if has('syntax') syntax enable " required for folding as well set hlsearch " highlight search results endif let g:python_highlight_builtin_funcs=1 if has('gui_running') set guioptions-=M " skip loading $VIMRUNTIME/menu.vim set guioptions-=m " hide menu which isn't loaded anyway set guioptions-=T " hide toolbar set guioptions-=r " hide scrollbar if has("gui_gtk2") set guifont=Consolas\ 11 else set guifont=Consolas:h9 end set columns=84 set lines=36 cd $HOME " might not be ideal... endif if has('title') | set title | endif " terminal title set history=8192 " command lines to remember set number " lines set ruler " write out the cursor position set showcmd " show number of lines/etc. selected set lazyredraw " when executing macros, untyped things set shortmess=atI " be less verbose and shut up vim set suffixes=.bak,~,.swp,.o,.log,.out " lower tab-completion priority set noerrorbells visualbell t_vb= " disable bells set scrolloff=3 " row context during scrolling set sidescrolloff=2 " col context during scrolling set incsearch " show first search result as we type set ignorecase " insensitive searching set smartcase " except when uppercase is used set infercase " use existing case when ins-completing set tabstop=8 shiftwidth=8 smarttab " 8 space tabs set virtualedit=block " allow cursor anywhere in visual block set foldmethod=marker " (performance issues with other methods) set foldlevelstart=99 " start with everything unfolded...? let c_syntax_for_h=1 " use C highlighting for .h files set nowrap " word wrapping is pretty weak in vim set nojoinspaces " don't use double-spaces for J and gq set ffs=unix,dos " ffs indeed set nobomb " bombs are bad ok set undofile " remember undos across files/sessions set diffopt+=iwhite " ignore whitespace in diff command set ttimeoutlen=50 " make changing modes a bit snappier set hidden " allow swapping out of unsaved buffers if has('mksession') set sessionoptions=blank,buffers,curdir,options,folds,tabpages,winsize,resize,winpos end if has('wildignore') " a bunch of stuff that may or may not do any good set wildignore="" set wildignore+=.git,.svn,.hg,pkg,tmp set wildignore+=*.bak,*.tmp,*.log,*.cache, set wildignore+=Desktop.ini,Thumbs.db,*.lnk,.DS_Store set wildignore+=*.zip,*.tar,*.tar.*, set wildignore+=*.suo,*.sln,*.pch,*.pdb,*.pgc,*.pgd set wildignore+=*.o,*.obj,*.elf,*.lib,*.a,*.dll,*.so,*.so.*,*.exe,*.out set wildignore+=*.png,*.jpg,*.jpeg,*.gif,*.pdf set wildignore+=__pycache__,*.pyc,*.pyo,*.pyd,*.npy,*.npz,*.pkl set wildignore+=*.gem,.bundle set wildignore+=CMakeCache.txt,CMakeFiles,install_manifest.txt set wildignore+=*.h5,*.npz endif " autocmd {{{1 fu! TabEight() setlocal tabstop=8 shiftwidth=8 noexpandtab softtabstop=0 endf fu! TabFour() setlocal tabstop=8 shiftwidth=4 expandtab softtabstop=4 endf fu! TabTwo() setlocal tabstop=2 shiftwidth=2 expandtab endf fu! TabBad() setlocal tabstop=4 shiftwidth=4 noexpandtab softtabstop=4 endf " set TabFour as default set tabstop=8 shiftwidth=4 expandtab softtabstop=4 if has('autocmd') augroup tabs au! au BufRead,BufNewFile PKGBUILD call TabTwo() au FileType ruby call TabTwo() au FileType nim call TabTwo() au BufRead,BufNewFile *.bt,*.1sc call TabFour() au BufRead,BufNewFile *.ys call TabTwo() au FileType javascript,processing call TabTwo() augroup END augroup whatever au! au BufRead,BufNewFile *.lib setlocal ft=spice au BufRead,BufNewFile *.bt setlocal ft=c au BufRead,BufNewFile *.1sc setlocal ft=c au BufRead,BufNewFile *.asm setlocal ft=lips au BufRead,BufNewFile *.nim setlocal ft=nim au BufRead,BufNewFile *.pde setlocal ft=processing augroup END augroup nocomment au! au FileType * setlocal fo-=c fo-=r fo-=o augroup END augroup nobells " good lord vim you are archaic au! au GUIEnter * set vb t_vb= augroup END fu! ResCur() " attempt to preserve cursor position if line("'\"") > 1 && line("'\"") <= line("$") normal! g`" return 1 endif endf augroup resCur au! au BufWinEnter * call ResCur() augroup END endif " keys/binds {{{1 set backspace=eol,start,indent " make backspace useful " tab completion in command-line if has('wildmenu') | set wildmenu | endif if &term =~ '^tmux' " https://unix.stackexchange.com/a/34723 " tmux will send xterm-style keys when xterm-keys is on execute "set =\e[1;*A" execute "set =\e[1;*B" execute "set =\e[1;*C" execute "set =\e[1;*D" endif " easy indent/unindent nn >> nn << " indentation without ending selection vn >gv vn ]\+>\s\+\)\+\zs') exec 'nn '.args[0].' '.args[1] exec 'ino '.args[0].' '.args[1] endf com! -nargs=+ Inn call Inn() Inn :w Inn :e Inn :bd Inn :w! Inn :e! Inn :bd! Inn :wall " np++ habits Inn Inn Inn :m-2 Inn :m+1 Inn :tabm -1 Inn :tabm +1 " jump to top and bottom Inn gg Inn G nn [1;5H gg nn [1;5F G ino [1;5H gg ino [1;5F G " hide search highlighting Inn :nohls " rebind annoying things " reflow text nn Q gq vn Q gq " split lines (opposite of J) nn K ik$ vn K " follow tag nn " delete line "nn D dd " execute vim code in visual selection vmap "xy:@x " this frees up x and X for use if you like exec "set =\[3;2~" Inn X " unfollow your leaders let leader="\\" " no-op nn : "ino " this doesn't workkkkkkkkk nm i i?r nm a a?r nn p "0p nn P "0P nn e :e **/* nn b :ls:b nn d :cd %:p:h:pwd nn . @: "nn ? :exec getline(".") nn , :Tab /,\zs "nn x :system('chmod +x %') | e " via bit101 nn f :E nn F :E . " alias :W to :w, via https://stackoverflow.com/a/3879737 cnoreabbrev W ((getcmdtype() is# ':' && getcmdline() is# 'W')?('w'):('W')) " misc {{{1 set list listchars=tab:»·,trail:·,extends:…,nbsp:‗ " including this in case i'm on a _really_ bad terminal: "set list listchars=tab:>-,trail:.,extends:>,nbsp:_ try | execute pathogen#infect() | catch /E117/ | endtry let g:netrw_banner=0 set background=dark try colorscheme property16 catch /E185/ colorscheme desert endtry " ctrlp {{{1 map :CtrlPBuffer let g:ctrlp_match_window='bottom,order:btt,min:1,max:24,results:24' " machine-specific configs {{{1 let s:hostname=hostname() if s:hostname == "phantom-pi" || s:hostname == "wraith" colo Tomorrow-Night endif