" .vimrc " http://briancarper.net/vim/vimrc - Some parts stolen from others. " " Don't just copy this. It has screwy stuff and depends on other stuff. " There's always a good possibility of there being broken or " experimental stuff in here. " set nocompatible syntax on filetype on filetype plugin on filetype plugin indent on set encoding=utf-8 set fileencoding=utf-8 set backup " I want all my backups in one directory if has('win32') let s:homedir = "$HOME/vimfiles" else let s:homedir = "$HOME" endif execute "set backupdir=" . s:homedir . "/.backups" set history=5000 set viminfo='1024,<0,s100,f0,r/tmp,r/mnt " see :h last-position-jump au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm'\"")|else|exe "norm $"|endif|endif " Appearance colorscheme gentooish if has('win32') set guifont=Terminus:h12:w6 hi StatusLine gui=NONE hi User1 gui=NONE hi User2 gui=NONE hi WildMenu gui=NONE else set guifont=Consolas\ 12 endif " Remove GUI menu and toolbar set guioptions-=T set guioptions-=m if(has("gui_running")) set cursorline set cursorcolumn endif set backspace=indent,eol,start set ruler set showcmd set number set wrap " Search set incsearch set hls set noignorecase set splitright " Sane defaults for tabs set tabstop=4 set shiftwidth=4 set softtabstop=4 set expandtab set smartindent " The text to return for a fold function! FoldText() let numlines = v:foldend - v:foldstart let firstline = getline(v:foldstart) "let spaces = 60 - len(firstline) return printf("%3d » %s ", numlines, firstline) endfunction set foldtext=FoldText() set fillchars=fold:· set foldcolumn=0 set foldmethod=syntax set foldlevelstart=1 "au BufNewFile,BufRead * syn sync fromstart set laststatus=2 set wildmenu " Bouncy parens set showmatch " Visual bells give me seizures set t_vb='' set nostartofline "set nowrapscan " Stolen from http://github.com/ciaranm/dotfiles-ciaranm/tree/master if (&termencoding == "utf-8") || has("gui_running") if v:version >= 700 set list listchars=eol:\ ,tab:»·,trail:·,precedes:…,extends:…,nbsp:‗ else set list listchars=eol:\ ,tab:»·,trail:·,extends:… endif else if v:version >= 700 set list listchars=eol:\ ,tab:>-,trail:.,extends:>,nbsp:_ else set list listchars=eol:\ ,tab:>-,trail:.,extends:> endif endif " Inspired by http://github.com/ciaranm/dotfiles-ciaranm/tree/master set statusline=%f\ %2*%m\ %1*%h%r%=[%{&encoding}\ %{&fileformat}\ %{strlen(&ft)?&ft:'none'}\ %{getfperm(@%)}]\ 0x%B\ %12.(%c:%l/%L%) " Filetype-specific fun if !exists("autocommands_loaded") let autocommands_loaded = 1 "autocmd QuickFixCmdPost * :copen | :set cwh=1 | :set ch=1 autocmd QuickFixCmdPost * :copen " CSS au bufNewFile,BufRead *.css map omargin: 0;padding: 0; au bufNewFile,BufRead *.css imap margin: 0;padding: 0; augroup Ruby au BufNewFile,BufRead *.{rb} setlocal tabstop=2|setlocal shiftwidth=2|setlocal softtabstop=2 au BufNewFile,BufRead *.{html.erb} setlocal tabstop=4|setlocal shiftwidth=4|setlocal softtabstop=4 "au BufNewFile *.rb :execute "0r " . s:homedir . "/skeleton/skeleton.ruby"|norm G au BufNewFile,BufRead *.{rb,rhtml,erb} nmap s :silent !pkill mongrel_rails;script/server -d au BufNewFile,BufRead *.{rb,rhtml,erb} nmap d :silent !pkill mongrel_rails;script/server -d au BufNewFile,BufRead *.{rhtml,erb} map o<%= %> au BufNewFile,BufRead *.{rhtml,erb} imap <%= %> au BufNewFile,BufRead *.{rhtml,erb} map o<% %> au BufNewFile,BufRead *.{rhtml,erb} imap <% %> au BufNewFile,BufRead */migrate/*.rb iabbrev a_c add_column au BufNewFile,BufRead */migrate/*.rb iabbrev r_c remove_column augroup END au BufNewFile *.{h,cpp} nmap m :silent make au BufNewFile *.h call Ifndef() au BufNewFile,BufRead *cpp map :!g++ % -o %:r au BufNewFile,BufRead *cpp map :!g++ % -o %:r && %:r au BufNewFile,BufRead *.java let java_highlight_functions="style" augroup PHP au BufNewFile,BufRead *.php nmap p Iprint_r(A); au BufNewFile,BufRead *.php nmap c iclass {function __construct() {}} au BufNewFile,BufRead *.php nmap i :s/$\?\(\S\+\)/$this->\1 = $\1;/ augroup END if has("win32") set wildignore+=*.bpk,*.bjk,*.diw,*.bmi,*.bdm,*.bfi,*.bdb,*.bxi vnoremap ii >'>oENDIF<<'<<_yiw_wPa au BufNewFile,BufRead *.bla setf bla au BufNewFile,BufRead *.bla nmap p :!"c:\Program Files\StatNeth\Blaise 4.8 Enterprise\Bin\B4CPars.exe" %:t:r.bpf au BufNewFile,BufRead *.bla nmap r :silent !RUNME.BAT au BufNewFile,BufRead *.bla nmap d :silent !del %:t:r.bdb au BufNewFile,BufRead vmap o :'<,'>g/^$/d'<'>I1 '<'>:I:'<,'>s:^\(\s*\)\(\d\+\) \(.*\):\1 C\2 (\2) "\3",:''>$s)<< endif au BufNewFile,BufRead *.{lisp,el,emacs} call LispHighlight() au BufNewFile,BufRead *.clj setlocal complete+=k~/.vim/clj-keys.txt|call ClojureHighlight() au BufNewFile,BufRead *.markdown setf markdown "autocmd BufNewFile,BufRead *.csv setf csv endif function! Ifndef() let str = toupper(expand("%:t:r")) execute "norm i#ifndef " . str norm o execute "norm i#define " . str norm o norm o norm i#endif endfunction " Use `:match none` to turn off the matches afterwards. function! CountLines() let i = 0 let s:regex = input("Regex>") execute('silent g/' . s:regex . '/let i = i + 1') execute("match Search /^.*" . s:regex . ".*$/") echo i . " lines match." norm '' endfunction " Highlight parens in light grey so they blend in. Backquoted should stand " out a bit more. function! LispHighlight() syn region lispList matchgroup=lispList start="(" skip="|.\{-}|" end=")" contains=@lispListCluster syn region lispBQList matchgroup=lispBQList start="`(" skip="|.\{-}|" end=")" contains=@lispListCluster hi lispList guifg=#555555 hi lispBQList guifg=#999999 endfunction function! ClojureHighlight() hi clojureParen0 guifg=#555555 endfunction " S-arrows suck vmap imap nmap vmap imap nmap " Indent fun vnoremap > >gv vnoremap < > vmap < " Right-drag will do a vblock select " nnoremap " nnoremap " vnoremap " vnoremap " Screwy default bindings for these, let's disable. "nnoremap nnoremap nnoremap nnoremap nnoremap nnoremap nnoremap bd :silent bufdo! bd nnoremap l :call CountLines() nnoremap w :setlocal nowrap! nnoremap h :nohls nnoremap q :cclose " Emacs-ish keybindings, oops noremap! noremap! noremap! noremap! noremap! " Annoying nnoremap q: nnoremap q/ nnoremap q? function! IsDiff(col) let hlID = diff_hlID(".", a:col) return hlID == 24 endfunction " Jump to the position in a diff line where the difference starts function! FindDiffOnLine() let c = 1 while c < col("$") if IsDiff(c) call cursor(".", c) return endif let c += 1 endwhile endfunction nnoremap ]c ]c:call FindDiffOnLine() nnoremap [c [c:call FindDiffOnLine() " Window movements; I do this often enough to warrant using up M-arrows on " this nnoremap nnoremap nnoremap _ nnoremap _ " Open window below instead of above nnoremap N :let sb=&sbset sbnewlet &sb=sb " Vertical equivalent of C-w-n and C-w-N nnoremap v :vnew nnoremap V :let spr=&sprset nosprvnewlet &spr=spr " I open new windows to warrant using up C-M-arrows on this nmap n nmap N nmap v nmap V " Maximize window (C-_ is a hard key combo to type) nmap _ " Horizontal window scrolling nnoremap zL nnoremap zH " I used this to record all of my :w's over the course of a day, for fun "cabbrev w =(getcmdtype()==':' && getcmdpos()==1 ? 'W' : 'w') "command! -nargs=* W :execute("silent !echo " . strftime("%Y-%m-%d %H:%M:%S") . " >> ~/timestamps")|w " Cut all lines matching a pattern and move them to the end of the file nnoremap fg :execute 'g/'.input("Search term: > ").'/norm ddGp' " Lining up code into columns using the nice Align plugin let g:loaded_alignmaps=1 vnoremap i= :AlignPush:AlignCtrl lp1P1:'<,'>Align =:AlignPop vnoremap i, :AlignPush:AlignCtrl lp0P1:'<,'>Align ,:AlignPop vnoremap i( :AlignPush:AlignCtrl lp0P0:'<,'>Align (:AlignPop vnoremap i@ :AlignPush:AlignCtrl lp0P0:'<,'>Align @:AlignPop " Nasty, I used these at work for something. I forget why, but I may need them again "nnoremap al vi(yop==:s/\A = $p:nohls "nnoremap "" :s/\v(^[^"]*)@ "vnoremap ra :'<,'>s/\w\+/@\1 = \1/:set nohls "vnoremap n 99<:'<,'>g/^$/d'<'>I1 '<'>:I:'<,'>s/\v^(\d+) (.*)/ "\1": "\2"/'>'<< "nnoremap n :s/\v^(\d+\S{-})\.\s+(.*)/ :number: "\1"\r :text: "\2"/ "nnoremap t :s/\v\s*(\S+)\s*(.*)/ - :name: \1\r :text: "\2"/\h function! DeleteUnlistedBuffer() if ! buflisted(bufname("%")) q endif endfunction noremap :call DeleteUnlistedBuffer() " Copy/pasting from Word DOC files (uggggggh) results in a horrid mess function! FixInvisiblePunctuation() silent! %s/\%u2019/\\'/g silent! %s/\%u2026/.../g silent! %s/\%uf0e0/->/g silent! %s/\%u0092/\\'/g silent! %s/\%u2013/--/g silent! %s/\%u2014/--/g silent! %s/’/\\'/g silent! %s/\%ua0/ /g silent! %s/“/"/g silent! %s/”/"/g retab endfunction " Remove weird keybindings from vimpager; plain Vim is good enough function! FixVimpager() if exists("g:loaded_less") && g:loaded_less set nolist set nofoldenable unmap unmap z unmap q unmap d endif endfunction function! SaveSearch() let g:hls_saved = &hls let g:search_saved = @/ endfunction function! RestoreSearch() let &hls = g:hls_saved let @/ = g:search_saved endfunction au VimEnter * :call FixVimpager() "au BufNewFile,BufRead,BufEnter * let b:usemarks=0 "au BufNewFile,BufRead,BufEnter * let b:cb_parent=1 "au BufNewFile,BufRead,BufEnter * let b:cb_bracket=1 "au BufNewFile,BufRead,BufEnter * let b:cb_acco=1 "au BufNewFile,BufRead,BufEnter * let b:cb_quotes=1 "au BufNewFile,BufRead,BufEnter * call Brackets() " "imap :call SaveSearch():call Surround('(', ')',0,0,'%',0):call RestoreSearch() "imap :call SaveSearch():call Surround('[', ']',0,0,'%',0):call RestoreSearch() "imap :call SaveSearch():call Surround('{', '}',0,0,'%',0):call RestoreSearch() " "au BufNewFile,BufRead,BufEnter * nnoremap ) :call SaveSearch()):call RestoreSearch() function! FixMarkdown() silent! %s,<\(/\?\)strong>,`,g endfunction set cmdheight=1 function! Pwd() let path=expand('%:h') return system('cd "' . path . '"; pwd -L') endfunction!