" .vimrc file " Recommended for vim >= 7, though works with vim 6 " By Lucas Oman " me@lucasoman.com " --enable-rubyinterp --prefix=/usr --enable-ruby set nocompatible syntax on filetype on " fast terminal for smoother redrawing set ttyfast " {{{ interface " lines, cols in status line set ruler " a - terse messages (like [+] instead of [Modified] " t - truncate file names " I - no intro message when starting vim fileless set shortmess=atI " display the number of (characters|lines) in visual mode, also cur command set showcmd " current mode in status line set showmode " max items in insert menu if version >= 700 set pumheight=8 endif " number column set number if version >= 700 set numberwidth=3 end " show fold column, fold by markers set foldcolumn=2 set foldmethod=marker " line numbering set showbreak=>\ " always show tab line if version >= 700 set showtabline=2 endif " highlight search matches set hlsearch " }}} " {{{ colors " tabe line colors highlight TabLineFill ctermfg=0 highlight TabLine ctermfg=7 ctermbg=0 cterm=none highlight TabLineSel ctermfg=7 cterm=bold ctermbg=0 " number column colors highlight LineNr ctermbg=0 ctermfg=4 " fold colors highlight Folded ctermbg=0 ctermfg=4 highlight FoldColumn ctermbg=0 ctermfg=4 " visual mode colors highlight Visual ctermbg=7 ctermfg=4 " dictionary menu colors highlight Pmenu ctermbg=7 ctermfg=0 highlight PmenuSel ctermbg=1 ctermfg=0 " the dark colors kill my eyes set background=light " }}} " {{{ behavior set shiftwidth=2 set tabstop=2 set cindent " show matching enclosing chars for .1 sec set showmatch set matchtime=1 " don't add linebreaks when wrapping set formatoptions=l " context while scrolling set scrolloff=3 " arrow keys, bs, space wrap to next/prev line set whichwrap=b,s,<,>,[,] " backspace over anything set backspace=indent,eol,start " case insensitive search if all lowercase set ignorecase smartcase " turn off bells, change to screen flash set visualbell " gf should use new tab, not current buffer if version >= 700 map gf :tabe else map gf :bad endif " }}} " {{{ filetype dependent " dictionary of php function names for c-x-c-k autocmd FileType php setlocal dictionary=~/.vim/funclist.txt "cake's thtml files need syntax highlighting autocmd BufNewFile,BufRead *.thtml setlocal filetype=php " ruby commenstring autocmd FileType ruby setlocal commentstring=#%s "}}} " {{{ mapped shortcuts " creates a fold from a block of code in {}s nmap \pf $va}zf nmap \ff :call ToggleFoldFuncs() " turns of highlighting nmap \/ :nohl " keep block highlighted when indenting vmap >> >gv vmap << " phpdoc comments nmap \c o/** * @author Lucas Oman (lucas.oman@bookit.com)* @access* @description* @param* @return*/ nmap \l :tabe /home/httpd/htdocs/lib/classes nmap :call ToggleColumns() imap :call ToggleColumns() nmap :call LoadSession() nmap :!updater set pastetoggle= " }}} "{{{ ToggleColumns() "make it easy to remove line number column etc. for cross-terminal copy/paste function ToggleColumns() if &number set nonumber set foldcolumn=0 let s:showbreaktmp = &showbreak set showbreak= else set number set foldcolumn=2 let &showbreak = s:showbreaktmp end endfunction "}}} "{{{ ToggleFoldFuncs() "turns on or off folding php functions function ToggleFoldFuncs() if &foldmethod == "marker" setlocal foldmethod=expr setlocal foldexpr=FoldFuncsExpr(v:lnum) else setlocal foldmethod=marker end endfunction function FoldFuncsExpr(num) "if match(getline(a:num),"function \w+\s?\(") > -1 if match(getline(a:num),"function ") > -1 return ">1" else return "=" endif endfunction "}}} "{{{ session stuff " don't store any options in sessions if version >= 700 set sessionoptions=blank,buffers,curdir,tabpages,winpos,folds endif " automatically update session, if loaded let s:sessionloaded = 0 function LoadSession() source Session.vim let s:sessionloaded = 1 endfunction function SaveSession() if s:sessionloaded == 1 mksession! end endfunction autocmd VimLeave * call SaveSession() " }}} "{{{ list stuff if version >= 700 autocmd BufNewFile,BufRead * highlight CursorLine NONE autocmd BufNewFile,BufRead *.list call ListFile() autocmd TabLeave *.list set nocursorline autocmd TabEnter *.list call ListFile() " 'install' list features function ListFile() setlocal foldmethod=expr setlocal foldexpr=ListFoldLevel(v:lnum) setlocal shiftwidth=4 setlocal tabstop=4 setlocal foldtext=ListFoldLine(v:foldstart) setlocal noshowmatch setlocal cindent if version >= 700 set cursorline highlight CursorLine ctermbg=3 cterm=NONE ctermfg=0 end " add [n]ew item below current map ,n o- =ListTimestamp()^la " mark item as [x] map ,x mz^rxf[hdf]$a=ListTimestamp()`z " mark item as [-] map ,- mz^r-f[hdf]$a=ListTimestamp()`z " mark item as = (in [p]rogress) map ,p mz^r=f[hdf]$a=ListTimestamp()`z " add/update [t]imestamp map ,t mz$a [^f[hd$a=ListTimestamp()`z endfunction " return properly formatted timestamp function ListTimestamp() return ' ['.strftime('%Y-%m-%d %T').']' endfunction " return fold line format function ListFoldLine(linenum) let s:count = 1 let s:spaces = '' while s:count <= &shiftwidth let s:spaces = s:spaces.' ' let s:count = s:count + 1 endwhile return substitute(getline(a:linenum),"\t",s:spaces,'g') endfunction " foldexpr function function ListFoldLevel(linenum) let s:prefix = '' let s:myline = getline(a:linenum) let s:nextline = getline(a:linenum+1) let s:mynumtabs = match(s:myline,"[^\t]",0) let s:nextnumtabs = match(s:nextline,"[^\t]",0) if s:nextnumtabs > s:mynumtabs " if this item has sub-items let s:level = s:nextnumtabs else " next item is either same or higher level let s:level = s:mynumtabs if s:nextnumtabs < s:mynumtabs " if next item has higher level, close this fold let s:prefix = '<' let s:level = s:nextnumtabs+1 end endif if a:linenum > 1 s:pline = getline(a:linenum-1) s:pnumtabs = match(s:pline,"[^\t]",0) if s:level < s:pnumtabs " if this is higher level than prev, start a new fold let s:prefix = '>' endif endif return s:prefix.s:level endfunction endif "}}} "new \ff {{{ nmap \t :%call Test() function Test() let s:line = getline('.') if (s:line =~ '^\s*function') endif endfunction "}}} "{{{ tab line stuff function MyTabLine() let s = '' for i in range(tabpagenr('$')) " select the highlighting if i + 1 == tabpagenr() let s .= '%#TabLineSel#' else let s .= '%#TabLine#' endif " set the tab page number (for mouse clicks) let s .= '%' . (i + 1) . 'T'.(i+1).'' " the filename is made by MyTabLabel() let s .= '%{MyTabLabel(' . (i + 1) . ')} ' endfor " after the last tab fill with TabLineFill and reset tab page nr let s .= '%#TabLineFill#%T' return s endfunction function MyTabLabel(n) let buflist = tabpagebuflist(a:n) let winnr = tabpagewinnr(a:n) let fullname = bufname(buflist[winnr - 1]) "let fullname = substitute(fullname,"(\w){1}\w*/","\1/","g") let fullname = substitute(fullname,".*/","","") if getbufvar(buflist[winnr - 1],"&mod") let modified = "+" else let modified = " " endif return modified.fullname endfunction if version >= 700 " Use the above tabe naming scheme set tabline=%!MyTabLine() endif "}}}