" vim: fdm=marker: " Recommended for vim >= 7; no guarantee of compatibility with earlier versions " Lucas Oman " --enable-rubyinterp --prefix=/usr --enable-ruby " Get latest from: http://github.com/lucasoman/Conf/raw/master/.vimrc " load pathogen call pathogen#runtime_append_all_bundles() "set t_Co=256 " misc options " {{{ interface " lines, cols in status line set ruler set rulerformat=%=%h%m%r%w\ %(%c%V%),%l/%L\ %P " a - terse messages (like [+] instead of [Modified] " t - truncate file names " I - no intro message when starting vim fileless " T - truncate long messages to avoid having to hit a key set shortmess=atTI " display the number of (characters|lines) in visual mode, also cur command set showcmd " current mode in status line set showmode " max items in popup menu set pumheight=8 " show number column set number set numberwidth=3 " show fold column, fold by markers set foldcolumn=2 set foldmethod=marker " indicate when a line is wrapped by prefixing wrapped line with '> ' set showbreak=>\ " always show tab line set showtabline=2 " highlight search matches set hlsearch " highlight position of cursor "set cursorline "set cursorcolumn "set statusline=%f\ %2*%m\ %1*%h%r%=[%{&encoding}\ %{&fileformat}\ %{strlen(&ft)?&ft:'none'}\ %{getfperm(@%)}]\ 0x%B\ %12.(%c:%l/%L%) "set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P "set laststatus=2 " }}} " {{{ behavior set nocompatible syntax on filetype on filetype plugin on " fast terminal for smoother redrawing set ttyfast set omnifunc=syntaxcomplete#Complete " indentation options " Note: smartindent is seriously outdated. cindent, even, is unnecessary. " Let the filetype plugins do the work. set shiftwidth=2 set tabstop=2 filetype indent on "set autoindent set cindent " show matching enclosing chars for .1 sec set showmatch set matchtime=1 " t: autowrap text using textwidth " l: long lines are not broken in insert mode " c: autowrap comments using textwidth, inserting leader " r: insert comment leader after " o: insert comment leader after o or O set formatoptions-=t set formatoptions+=lcro set textwidth=80 " 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 " show our whitespace set listchars=tab:\|\ ,trail:. "set list " complete to longest match, then list possibilities set wildmode=longest,list " turn off swap files set noswapfile " options for diff mode set diffopt=filler set diffopt+=context:4 set diffopt+=iwhite set diffopt+=vertical " keep a lot of history set history=100 " keep lots of stuff set viminfo+=:100 set viminfo+=/100 " don't duplicate an existing open buffer set switchbuf=useopen " }}} " {{{ colors highlight SpecialKey cterm=bold ctermfg=0 " tabe line colors highlight TabLineFill ctermfg=DarkGray highlight TabLine ctermfg=4 ctermbg=DarkGray cterm=bold highlight TabLineSel ctermfg=7 cterm=none ctermbg=DarkGray " number column colors highlight LineNr cterm=none ctermbg=none ctermfg=4 " fold colors highlight Folded cterm=none ctermbg=none ctermfg=4 highlight FoldColumn cterm=none ctermbg=none ctermfg=4 " visual mode colors highlight Visual ctermbg=7 ctermfg=4 " dictionary menu colors highlight Pmenu ctermbg=7 ctermfg=0 highlight PmenuSel ctermbg=Yellow ctermfg=0 " diff colors highlight DiffAdd cterm=none ctermbg=4 highlight DiffDelete cterm=none ctermbg=4 highlight DiffChange cterm=none ctermbg=4 highlight DiffText cterm=none ctermbg=4 " keep cursor column last so it overrides all others highlight CursorColumn cterm=none ctermbg=Black highlight CursorLine cterm=none ctermbg=Black highlight Search cterm=none ctermbg=7 ctermfg=4 " make sure bold is disabled or your terminal will look like the vegas strip set background=dark " }}} " {{{ filetype dependent autocmd BufNewFile,BufRead *.html setlocal commentstring= " ruby commenstring autocmd FileType ruby setlocal commentstring=#%s " make help navigation easier autocmd FileType help nnoremap autocmd FileType help nnoremap "}}} "php syntax options {{{ let php_sql_query = 1 "for SQL syntax highlighting inside strings let php_htmlInStrings = 1 "for HTML syntax highlighting inside strings "php_baselib = 1 "for highlighting baselib functions "php_asp_tags = 1 "for highlighting ASP-style short tags "php_parent_error_close = 1 "for highlighting parent error ] or ) "php_parent_error_open = 1 "for skipping an php end tag, if there exists an open ( or [ without a closing one "php_oldStyle = 1 "for using old colorstyle "php_noShortTags = 1 "don't sync as php let php_folding = 1 "for folding classes and functions " }}} "netrw options {{{ let g:netrw_sort_sequence = '[\/]$,\.php,\.phtml,*,\.info$,\.swp$,\.bak$,\~$' "}}} "{{{taglist options " set the names of flags let tlist_php_settings = 'php;c:class;f:function;d:constant;p:property' " close all folds except for current file let Tlist_File_Fold_Auto_Close = 1 " make tlist pane active when opened let Tlist_GainFocus_On_ToggleOpen = 1 " width of window let Tlist_WinWidth = 60 " close tlist when a selection is made let Tlist_Close_On_Select = 1 " show the prototype let Tlist_Display_Prototype = 1 " show tags only for current buffer let Tlist_Show_One_File = 1 "}}} "{{{html options let html_use_css = 1 "}}} " mappings " {{{ general let mapleader = "\\" " easier move screen up/down nmap nmap nmap za " turns off highlighting nmap / :nohl " search for highlighted text vmap // y/" " keep block highlighted when indenting vmap >> >gv vmap << fx :setlocal filetype=xml:%s/>\r:1,$!xmllint --format -:setlocal foldmethod=indent " comment/uncomment highlighted block vmap cc :s!^!//! vmap cu :s!^//!! " open local projects list file nmap l :70vsplit ~/Dropbox/projects.list " fix syntax highlighting nmap ss :syntax sync fromstart " toggle the tag list nmap tl :TlistToggle " toggle gundo nmap gu :GundoToggle " make arrow keys useful " use them to swap between split windows nmap h nmap l nmap k nmap j com -range XselCopy :,w !xsel -i -b com XselPaste :r !xsel -o -b vmap xc :XselCopy nmap xp :XselPaste "}}} " php {{{ " syntax check nmap ps :!php -l % " run current script nmap pr :!php % \| less -F " lookup keyword in function reference nmap ph :!pman " create test method nmap pt o/**@test/public function " phpdoc comments nmap cc o/**$Rev$$Date$$Id$$Author$$HeadURL$@package /kkk$a nmap cb o/**@param @return @example /kkkkk$a nmap cv o/**@var /kkk$a nmap cp o/**@author Lucas Oman @param @return @example /kkkkkk$a "}}} " svn {{{ " set svn keywords nmap sk :!svn propset svn:keywords "Rev Date Id Author HeadURL" % nmap sp :call SvnPushFile() com! -nargs=1 Sstat :call SvnStatus("") " view status of given path fun! SvnStatus(path) tabe setl buftype=nofile exe "r !svn st ".a:path endfunction " call script to copy file to appropriate location in htdocs fun! SvnPushFile() let line = getline('.') let file = strpart(l:line,8) exe "!~/lib/updatedev.php ".l:file endfunction "}}} "f keys {{{ nmap :call ToggleColumns() imap :call ToggleColumns() nmap :Nload nmap :NERDTree set pastetoggle= " nmap :!updatedev.php %:p nmap :call WriteTrace() nmap \ph " " don't use; terminal full-screen " " }}} "{{{ list file let g:listFile_ranks = ['=','1','2','3','4','5','!','o','-','?','x'] autocmd BufNewFile,BufRead *.list call MyListFileStuff() fun! MyListFileStuff() nmap ,! :Lmark ! vmap ,! :Lmark ! nmap ,tq :Ltag quick vmap ,tq :Ltag quick nmap ,sq :Lsearch tag quick nmap ,d ,x,t,r endfunction "}}} " minor helpful stuff fun! ToggleColumns() "{{{ "make it easy to remove line number column etc. for cross-terminal copy/paste 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 "}}} fun! WriteTrace() "{{{ let lineNum = line('.') let lineFile = bufname('%') let lineVal = getline(lineNum) let allLines = readfile($HOME."/trace.txt") let allLines = add(allLines,lineFile.":".lineNum) let allLines = add(allLines,lineVal) let allLines = add(allLines,"") call writefile(allLines,$HOME."/trace.txt") endfunction "}}} "{{{ctags stuff nmap tf :call CtagsFind(expand('')) com! -nargs=+ Tf :call CtagsFind("") " split window and search for tag nmap ts :exe('stj '.expand('')) " open new tab and search for tag fun! CtagsFind(keyword) tabe exe "tj ".a:keyword endfunction "}}} " stand-alone components "{{{ TAB-COMPLETE and SNIPPETS " add new snippets as regex=>completion " first match encountered is used let s:snippets = {} let s:snippets['^\s*if$'] = " () {\}\k^f)i" let s:snippets['function$'] = " () {\}\k^f(i" let s:snippets['^\s*class$'] = " {\}\kt{i" let s:snippets['^\s*interface$'] = " {\}\kt{i" let s:snippets['^\s*foreach$'] = " () {\}\k^f)i" let s:snippets['^\s*while$'] = " () {\}\k^f)i" " when tab is pressed: " 1) checks snippets for matches, return match if there is one " 2) if character behind cursor is whitespace, just return a tab " 3) if word behind cursor contains a slash, try filename complete " 4) otherwise, try to ctrl-p complete fun! CleverTab() if pumvisible() return "\" endif if col('.') > 1 let beginning = strpart( getline('.'), 0, col('.')-1 ) let words = split(l:beginning,' ') let thisWord = l:words[-1] for key in keys(s:snippets) if l:beginning =~ key return s:snippets[key] endif endfor else let beginning = '' endif if l:beginning == '' || l:beginning =~ '\s$' return "\" elseif (l:thisWord =~ '/') return "\\" else return "\\" "return "\" endif endfunction imap =CleverTab() "}}} "CODE GREP {{{ " grep for given string (second is case insensitive) " simply a wrapper for vimgrep " eg: :F /badxmlexception/ lib php com! -nargs=+ F :call CommandFind("") fun! CommandFind(args) tabe let parts = split(a:args,' ') exe "vimgrep ".l:parts[0]." ".l:parts[1]."/**/*.".l:parts[2] exe "copen" endfunction "}}} "{{{ TAB MGMT " Some useful bits for managing tabs. " Also changes format of tab line. " Commands and shortcuts: " \oc - open dir of current file in new tab " H - navigate to tab to the left " L - navigate to tab to the right " C-l - move current tab left " C-h - move current tab right " gf - changes default behavior from opening file under cursor in current window to opening in new tab nmap oc :tabe %:h " quicker aliases for navigating tabs nmap H gT nmap L gt " move tab left or right nmap :call MoveTab(0) nmap :call MoveTab(-2) " gf should use new tab, not current buffer map gf :tabe "tab line fun! 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 fun! MyTabLabel(n) let buflist = tabpagebuflist(a:n) let winnr = tabpagewinnr(a:n) let fullname = bufname(buflist[winnr - 1]) " show a/b/c/filename.ext "let fullname = substitute(fullname,"(\w){1}\w*/","\1/","g") " show filename.ext let fullname = substitute(fullname,".*/","","") if getbufvar(buflist[winnr - 1],"&mod") let modified = "+" else let modified = " " endif return modified.fullname endfunction " Use the above tabe naming scheme set tabline=%!MyTabLine() "tab moving fun! MoveTab(n) let which = tabpagenr() let which = which + a:n exe "tabm ".which endfunction "}}}