" .vimrc " http://briancarper.net/vim/vimrc - Some parts stolen from others. " 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=Terminus\ 10 endif set guioptions-=T set guioptions-=m if(has("gui_running")) set cursorline 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 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") 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 !"c:\Program Files\StatNeth\Blaise 4.8 Enterprise\Bin\dep.exe" %:t:r /MEGADS au BufNewFile,BufRead *.bla nmap d :silent !del %:t:r.bdb endif au BufNewFile,BufRead *.{lisp,el,emacs} call LispHighlight() au BufNewFile,BufRead *.clj setlocal complete+=k~/.vim/clj-keys.txt|call ClojureHighlight() 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 " 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 nmap bd :silent bufdo! bd nmap l :call CountLines() nmap w :setlocal nowrap! nmap h :nohls nmap q :cclose " Emacs-ish keybindings, oops noremap! noremap! noremap! noremap! noremap! " Annoying nmap q: nmap q/ nmap q? function! IsDiff(col) let hlID = diff_hlID(".", a:col) return hlID == 24 endfunction 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 etc. nnoremap nnoremap nnoremap _ nnoremap _ nmap v :vnew nmap V :let spr=&sprset nosprvnewlet &spr=spr nnoremap N :let sb=&sbset sbnewlet &sb=sb nmap n nmap N nmap v nmap V nmap _ nnoremap zL nnoremap zH "--------------------------------------------------------------------- " Author: Jean Jordaan " Source: (http://groups.yahoo.com/group/vim/message/16444 " Date: Mon Feb 26, 2001 5:34 am " Subject: Some functions to read mailing list digests with Vim. " function! Uniq(...) range " use arguments if two passed if a:0 == 2 let a = a:1 let z = a:2 " use range else let a = a:firstline let z = a:lastline endif while (a <= z) let str1 = getline(a) let str2 = getline(a+1) if (str1 == str2) execute a . "delete" let z = z - 1 else let a = a + 1 endif endwhile endfunction command! -nargs=0 -range Uniq ,call Uniq() "cabbrev w =(getcmdtype()==':' && getcmdpos()==1 ? 'W' : 'w') "command! -nargs=* W :execute("silent !echo " . strftime("%Y-%m-%d %H:%M:%S") . " >> ~/timestamps")|w nnoremap fg :execute 'g/'.input("Search term: > ").'/norm ddGp' vmap o :'<,'>g/^$/d'<'>I1 '<'>:I:'<,'>s:^\(\s*\)\(\d\+\) \(.*\):\1 C\2 (\2) "\3",:''>$s)<< set wildignore+=*.bpk,*.bjk,*.diw,*.bmi,*.bdm,*.bfi,*.bdb,*.bxi 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:· vmap i= :AlignPush:AlignCtrl lp1P1:'<,'>Align =:AlignPop vmap i, :AlignPush:AlignCtrl lp0P1:'<,'>Align ,:AlignPop vmap i( :AlignPush:AlignCtrl lp0P0:'<,'>Align (:AlignPop vmap i@ :AlignPush:AlignCtrl lp0P0:'<,'>Align @:AlignPop nmap al vi(yop==:s/\A = $p:nohls nmap ss :set foldmethod=syntax nmap "" :s/\v(^[^"]*)@ nmap e :g/^\s*$/d " From https://launchpad.net/bzr-vim-commands, slightly modified command! -complete=file -nargs=* Bzr call s:RunShellCommand('bzr '.) command! -complete=file -nargs=* Git call s:RunShellCommand('git '.) command! -complete=file -nargs=* Hg call s:RunShellCommand('hg '.) command! -complete=file -nargs=* Svn call s:RunShellCommand('svn '.) command! -complete=file -nargs=+ Shell call s:RunShellCommand() function! s:RunShellCommand(cmdline) botright new setlocal buftype=nofile bufhidden=wipe noswapfile nowrap call setline(1,a:cmdline) call setline(2,substitute(a:cmdline,'.','=','g')) execute 'silent $read !'.escape(a:cmdline,'()%#') setlocal nomodifiable if search('\m\C^--- .*\n+++ .*\n@@','n') setlocal filetype=diff endif if a:cmdline =~ '\m\C^git ' match Statement /\v\C/ elseif a:cmdline =~ '\m\C^bzr log' match Statement /\v-{50,}/ endif endfunction function! DeleteUnlistedBuffer() if ! buflisted(bufname("%")) q endif endfunction nmap :call DeleteUnlistedBuffer() vmap ra :'<,'>s/\w\+/@\1 = \1/:set nohls function! FixInvisiblePunctuation() silent! %s/\%u2019/'/g silent! %s/\%u2026/.../g silent! %s/\%uf0e0/->/g endfunction vmap n 99<:'<,'>g/^$/d'<'>I1 '<'>:I:'<,'>s/\v^(\d+) (.*)/ "\1": "\2"/'>'<< nmap n :s/\v^(\d+\S{-})\.\s+(.*)/ :number: "\1"\r :text: "\2"/ nmap t :s/\v\s*(\S+)\s*(.*)/ - :name: \1\r :text: "\2"/\h let g:loaded_alignmaps=1 "function! MoveToClosingParen() " let c = getline(".")[col(".") - 1] " if col(".") == col("$") || c != ")" " call search(")", "W") " endif " let pos = getpos(".") " let pos[2] = pos[2] + 1 " call setpos(".", pos) "endfunction " "function! MoveLeft() " let pos = getpos(".") " let pos[2] = pos[2] - 1 " call setpos(".", pos) "endfunction! " "function! MoveRight() " let pos = getpos(".") " let pos[2] = pos[2] + 1 " call setpos(".", pos) "endfunction! " "function! DeleteOrMoveLeft() " let prevchar = getline(".")[col(".") - 2] " let thischar = getline(".")[col(".") - 1 ] " if prevchar == ")" " call MoveLeft() " return "" " elseif prevchar == "(" " if thischar == ")" " call MoveRight() " return "" " else " call MoveLeft() " return "" " end " else " return "" " endif "endfunction " "function! DeleteOrDoNothing() " let prevchar = getline(".")[col(".") - 2] " let thischar = getline(".")[col(".") - 1] " let nextchar = getline(".")[col(".")] " if thischar == "(" " if nextchar == ")" " call MoveRight() " call MoveRight() " return "" " else " return "" " end " elseif thischar == ")" " if prevchar == "(" " call MoveRight() " return "" " else " return "" " end " else " return "\" " endif "endfunction " "inoremap =DeleteOrMoveLeft() "inoremap =DeleteOrDoNothing() "inoremap ( () "inoremap ) :call MoveToClosingParen() "