" ~/.vimrc " vim:set ft=vim et tw=78 sw=2: if has("win32") let &runtimepath = substitute(&runtimepath,'\(Documents and Settings\|Users\)[\\/][^\\/,]*[\\/]\zsvimfiles\>','.vim','g') endif silent! execute pathogen#infect("~/src/vim/vendor/{}") silent! execute pathogen#infect("~/src/vim/bundle{}") " Section: Options {{{1 " --------------------- set nocompatible set autoindent set autowrite " Automatically save before commands like :next and :make set backspace=2 set backupskip+=*.tmp,crontab.* if has("balloon_eval") && has("unix") set ballooneval endif if exists("&breakindent") set breakindent showbreak=+++ endif set cmdheight=2 set commentstring=#\ %s set complete-=i " Searching includes can be slow set dictionary+=/usr/share/dict/words set display=lastline if has("eval") let &fileencodings = substitute(&fileencodings,"latin1","cp1252","") endif set fileformats=unix,dos,mac set grepprg=grep\ -rnH\ --exclude='.*.swp'\ --exclude='*~'\ --exclude=tags if has("eval") let &highlight = substitute(&highlight,'NonText','SpecialKey','g') endif set incsearch " Incremental search set laststatus=2 " Always show status line set lazyredraw if (&termencoding ==# 'utf-8' || &encoding ==# 'utf-8') && version >= 700 let &listchars = "tab:\u21e5\u00b7,trail:\u2423,extends:\u21c9,precedes:\u21c7,nbsp:\u26ad" let &fillchars = "vert:\u259a,fold:\u00b7" else set listchars=tab:>\ ,trail:-,extends:>,precedes:< endif set modeline set modelines=5 " Debian likes to disable this set mousemodel=popup set pastetoggle= set scrolloff=1 set showcmd " Show (partial) command in status line. set showmatch " Show matching brackets. set smartcase " Case insensitive searches become sensitive with capitals set smarttab " sw at the start of the line, sts everywhere else if exists("+spelllang") set spelllang=en_us endif set spellfile=~/.vim/spell/en.utf-8.add set splitbelow " Split windows at bottom set statusline=[%n]\ %<%.99f\ %h%w%m%r%{SL('CapsLockStatusline')}%y%{SL('fugitive#statusline')}%#ErrorMsg#%{SL('SyntasticStatuslineFlag')}%*%=%-14.(%l,%c%V%)\ %P " set suffixes+=.aux,.dvi,.swo " Lower priority in wildcards set tags+=../tags;/ set timeoutlen=1200 " A little bit more time for macros set ttimeoutlen=50 " Make Esc work faster if exists('+undofile') set undofile endif if v:version >= 700 set viminfo=!,'20,<50,s10,h endif set visualbell set virtualedit=block set wildmenu set wildmode=longest:full,full set wildignore+=tags set winaltkeys=no if v:version >= 600 set autoread set foldmethod=marker set printoptions=paper:letter set sidescrolloff=5 set mouse=nvi endif if v:version < 602 || $DISPLAY =~ '^localhost:' || $DISPLAY == '' set clipboard-=exclude:cons\\\|linux set clipboard+=exclude:cons\\\|linux\\\|screen.* if $TERM =~ '^screen' set mouse= endif endif if !has("gui_running") && $DISPLAY == '' || !has("gui") set mouse= endif if $TERM =~ '^screen' if exists("+ttymouse") && &ttymouse == '' set ttymouse=xterm endif if $TERM != 'screen.linux' && &t_Co == 8 set t_Co=16 endif endif if $TERM == 'xterm-color' && &t_Co == 8 set t_Co=16 endif if has("dos16") || has("dos32") || has("win32") || has("win64") if $PATH =~? 'cygwin' && ! exists("g:no_cygwin_shell") set shell=bash set shellpipe=2>&1\|tee set shellslash endif elseif has("mac") set backupskip+=/private/tmp/* endif " Plugin Settings {{{2 if v:version >= 700 let g:is_bash = 1 let g:lisp_rainbow = 1 let g:markdown_fenced_languages = ['ruby', 'html', 'javascript', 'css', 'erb=eruby.html', 'bash=sh'] let g:liquid_highlight_types = g:markdown_fenced_languages + ['jinja=liquid', 'html+erb=eruby.html', 'html+jinja=liquid.html'] let g:netrw_list_hide = '^\.,^tags$' let g:ruby_minlines = 500 let g:rubycomplete_buffer_loading = 1 let g:rubycomplete_rails = 1 let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell' let g:CSApprox_verbose_level = 0 let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard'] let g:miniBufExplForceSyntaxEnable = 1 let g:NERDCreateDefaultMappings = 0 let g:NERDSpaceDelims = 1 let g:NERDShutUp = 1 let g:NERDTreeHijackNetrw = 0 let g:paredit_leader = "" let g:ragtag_global_maps = 1 let g:space_disable_select_mode = 1 let g:syntastic_enable_signs = 1 let g:syntastic_auto_loc_list = 1 let g:VCSCommandDisableMappings = 1 let g:Tex_CompileRule_dvi = 'latex -interaction=nonstopmode -src-specials $*' let g:Tex_SmartKeyQuote = 0 let g:showmarks_enable = 0 let g:surround_{char2nr('-')} = "<% \r %>" let g:surround_{char2nr('=')} = "<%= \r %>" let g:surround_{char2nr('8')} = "/* \r */" let g:surround_{char2nr('s')} = " \r" let g:surround_{char2nr('^')} = "/^\r$/" let g:surround_indent = 1 let g:dbext_default_history_file = "/tmp/".$LOGNAME.".dbext_sql_history.txt" function! s:try(cmd, default) if exists(':' . a:cmd) && !v:count let tick = b:changedtick exe a:cmd if tick == b:changedtick execute 'normal! '.a:default endif else execute 'normal! '.v:count.a:default endif endfunction nnoremap gJ :call try('SplitjoinJoin', 'gJ') nnoremap J :call try('SplitjoinJoin', 'J') nnoremap gS :SplitjoinSplit nnoremap S :call try('SplitjoinSplit', 'S') nnoremap r :call try('SplitjoinSplit', "r\015") endif " }}}2 " Section: Commands {{{1 " ----------------------- if has("eval") function! SL(function) if exists('*'.a:function) return call(a:function,[]) else return '' endif endfunction command! -bar -nargs=1 -complete=file E :exe "edit ".substitute(,'\(.*\):\(\d\+\):\=$','+\2 \1','') command! -bar -nargs=? -bang Scratch :silent enew|set buftype=nofile bufhidden=hide noswapfile buflisted filetype= modifiable command! -bar -count=0 RFC :e http://www.ietf.org/rfc/rfc.txt|setl ro noma function! s:scratch_maps() abort nnoremap == :Scratch nnoremap =" :Scratchput1delete _filetype detect nnoremap =* :Scratchput *1delete _filetype detect nnoremap =f :Scratchsetfiletype endfunction function! Synname() if exists("*synstack") return map(synstack(line('.'),col('.')),'synIDattr(v:val,"name")') else return synIDattr(synID(line('.'),col('.'),1),'name') endif endfunction command! -bar Invert :let &background = (&background=="light"?"dark":"light") function! Fancy() if &number if has("gui_running") let &columns=&columns-12 endif windo set nonumber foldcolumn=0 if exists("+cursorcolumn") set nocursorcolumn nocursorline endif else if has("gui_running") let &columns=&columns+12 endif windo set number foldcolumn=4 if exists("+cursorcolumn") set cursorline endif endif endfunction command! -bar Fancy :call Fancy() function! OpenURL(url) if has("win32") exe "!start cmd /cstart /b ".a:url."" elseif $DISPLAY !~ '^\w' exe "silent !sensible-browser \"".a:url."\"" else exe "silent !sensible-browser -T \"".a:url."\"" endif redraw! endfunction command! -nargs=1 OpenURL :call OpenURL() " open URL under cursor in browser nnoremap gb :OpenURL nnoremap gA :OpenURL http://www.answers.com/ nnoremap gG :OpenURL http://www.google.com/search?q= nnoremap gW :OpenURL http://en.wikipedia.org/wiki/Special:Search?search= function! Run() let old_makeprg = &makeprg let old_errorformat = &errorformat try let cmd = matchstr(getline(1),'^#!\zs[^ ]*') if exists('b:run_command') exe b:run_command elseif cmd != '' && executable(cmd) wa let &makeprg = matchstr(getline(1),'^#!\zs.*').' %' make elseif &ft == 'mail' || &ft == 'text' || &ft == 'help' || &ft == 'gitcommit' setlocal spell! elseif exists('b:rails_root') && exists(':Rake') wa Rake elseif &ft == 'cucumber' wa compiler cucumber make % elseif &ft == 'ruby' wa if executable(expand('%:p')) || getline(1) =~ '^#!' compiler ruby let &makeprg = 'ruby' make % elseif expand('%:t') =~ '_test\.rb$' compiler rubyunit let &makeprg = 'ruby' make % elseif expand('%:t') =~ '_spec\.rb$' compiler rspec let &makeprg = 'rspec' make % elseif &makeprg ==# 'bundle' make elseif executable('pry') && exists('b:rake_root') execute '!pry -I"'.b:rake_root.'/lib" -r"%:p"' elseif executable('pry') !pry -r"%:p" else !irb -r"%:p" endif elseif &ft == 'html' || &ft == 'xhtml' || &ft == 'php' || &ft == 'aspvbs' || &ft == 'aspperl' wa if !exists('b:url') call OpenURL(expand('%:p')) else call OpenURL(b:url) endif elseif &ft == 'vim' w if exists(':Runtime') return 'Runtime %' else unlet! g:loaded_{expand('%:t:r')} return 'source %' endif elseif &ft == 'sql' 1,$DBExecRangeSQL elseif expand('%:e') == 'tex' wa exe "normal :!rubber -f %:r && xdvi %:r >/dev/null 2>/dev/null &\" elseif &ft == 'dot' let &makeprg = 'dotty' make % else wa if &makeprg =~ '%' make else make % endif endif return '' finally let &makeprg = old_makeprg let &errorformat = old_errorformat endtry endfunction command! -bar Run :execute Run() endif " Section: Mappings {{{1 " ---------------------- if has('digraphs') digraph ./ 8230 endif nnoremap Y y$ nnoremap Q :q if exists(":nohls") nnoremap :nohls endif inoremap `^ nnoremap =p m`=ap`` " nnoremap == == vnoremap > >gv vnoremap Igv inoremap ^ =substitute(&commentstring,' \=%s\>'," -*- ".&ft." -*- vim:set ft=".&ft." ".(&et?"et":"noet")." sw=".&sw." sts=".&sts.':','') cnoremap inoremap o inoremap O inoremap inoremap ^ inoremap $ noremap! noremap! inoremap u if has("eval") command! -buffer -bar -range -nargs=? Slide :exe 'norm m`'|exe ',move'.(( < 0 ? -1 : )+(=='' ? 1 : ))|exe 'norm ``' endif map map! if has("gui_running") map :Fancy endif map :cnext map :cc map :cprev nmap :if &previewwindowpcloseelseif exists(':Gstatus')exe 'Gstatus'elselsendif nmap :if exists(':Glcd')exe 'Glcd'elseif exists(':Rlcd')exe 'Rlcd'elselcd %:hendif map :wamake map :Run map :let tagsfile = tempname()\|silent exe "!ctags -f ".tagsfile." \"%\""\|let &l:tags .= "," . tagsfile\|unlet tagsfile map :if exists(":BufExplorer")exe "BufExplorer"elsebuffersendif map :bdelete noremap noremap! map l CapsLockToggle imap CapsLockToggle imap c CapsLockToggle nmap du SpeedDatingNowUTC nmap dx SpeedDatingNowLocal " Merge consecutive empty lines and clean up trailing whitespace map fm :g/^\s*$/,/\S/-j%s/\s\+$// map v :so ~/.vimrc inoremap =repeat(complete(col('.'),map(["%Y-%m-%d %H:%M:%S","%a, %d %b %Y %H:%M:%S %z","%Y %b %d","%d-%b-%y","%a %b %d %T %Z %Y"],'strftime(v:val)')+[localtime()]),0) " Section: Autocommands {{{1 " -------------------------- if has("autocmd") if $HOME !~# '^/Users/' filetype off " Debian preloads this before the runtimepath is set endif if version>600 filetype plugin indent on else filetype on endif augroup Misc " {{{2 autocmd! autocmd FileType netrw nnoremap gr :grep =shellescape(fnamemodify(expand('%').'/'.getline('.'),':.'),1) -r autocmd FileType netrw call s:scratch_maps() autocmd FileType gitcommit if getline(1)[0] ==# '#' | call s:scratch_maps() | endif autocmd FocusLost * silent! wall autocmd FocusGained * if !has('win32') | silent! call fugitive#reload_status() | endif autocmd SourcePre */macros/less.vim set laststatus=0 cmdheight=1 if v:version >= 700 && isdirectory(expand("~/.trash")) autocmd BufWritePre,BufWritePost * if exists("s:backupdir") | set backupext=~ | let &backupdir = s:backupdir | unlet s:backupdir | endif autocmd BufWritePre ~/* \ let s:path = expand("~/.trash").strpart(expand(":p:~:h"),1) | \ if !isdirectory(s:path) | call mkdir(s:path,"p") | endif | \ let s:backupdir = &backupdir | \ let &backupdir = escape(s:path,'\,').','.&backupdir | \ let &backupext = strftime(".%Y%m%d%H%M%S~",getftime(expand(":p"))) endif autocmd User Rails Rnavcommand steps \ features/step_definitions -suffix=_steps.rb -default=controller() autocmd User Fugitive \ if filereadable(fugitive#buffer().repo().dir('fugitive.vim')) | \ source `=fugitive#buffer().repo().dir('fugitive.vim')` | \ endif autocmd BufNewFile */init.d/* \ if filereadable("/etc/init.d/skeleton") | \ 0r /etc/init.d/skeleton | \ $delete | \ silent! execute "%s/\\$\\(Id\\):[^$]*\\$/$\\1$/eg" | \ endif | \ set ft=sh | 1 autocmd BufNewFile */.netrc,*/.fetchmailrc,*/.my.cnf,*/.pam_environment let b:chmod_new="go-rwx" autocmd BufWritePost,FileWritePost * if exists("b:chmod_new")| \ silent! execute "!chmod ".b:chmod_new." "| \ unlet b:chmod_new| \ endif autocmd BufWritePost,FileWritePost ~/.Xdefaults,~/.Xresources silent! !xrdb -load % >/dev/null 2>&1 autocmd BufWritePre,FileWritePre /etc/* if &ft == "dns" | \ exe "normal msHmt" | \ exe "gl/^\\s*\\d\\+\\s*;\\s*Serial$/normal ^\" | \ exe "normal g`tztg`s" | \ endif autocmd BufReadPre *.pdf setlocal binary " autocmd BufReadCmd *.jar call zip#Browse(expand("")) autocmd CursorHold,BufWritePost,BufReadPost,BufLeave * \ if !$VIMSWAP && isdirectory(expand(":h")) | let &swapfile = &modified | endif augroup END " }}}2 augroup FTCheck " {{{2 autocmd! autocmd BufNewFile,BufRead */apache2/[ms]*-*/* set ft=apache autocmd BufNewFile,BufRead *named.conf* set ft=named autocmd BufNewFile,BufRead *.cl[so] set ft=tex autocmd BufNewFile,BufRead *.vb set ft=vbnet autocmd BufNewFile,BufRead *.CBL,*.COB,*.LIB set ft=cobol autocmd BufNewFile,BufRead /var/www/* \ let b:url=expand(":s?^/var/www/?http://localhost/?") " autocmd BufNewFile,BufRead,StdinReadPost * " \ if !did_filetype() && (getline(1) =~ '^!!\@!' " \ || getline(2) =~ '^!!\@!' || getline(3) =~ '^!' " \ || getline(4) =~ '^!' || getline(5) =~ '^!') | " \ setf router | " \ endif " autocmd BufRead * if ! did_filetype() && getline(1)." ".getline(2). " \ " ".getline(3) =~? '<\%(!DOCTYPE \)\=html\>' | setf html | endif autocmd BufNewFile,BufRead *.txt,README,INSTALL,NEWS,TODO if &ft == ""|set ft=text|endif augroup END " }}}2 augroup FTOptions " {{{2 autocmd! autocmd FileType c,cpp,cs,java setlocal commentstring=//\ %s autocmd Syntax javascript setlocal isk+=$ autocmd FileType xml,xsd,xslt,javascript setlocal ts=2 autocmd FileType text,txt,mail setlocal ai com=fb:*,fb:-,n:> autocmd FileType sh,zsh,csh,tcsh inoremap ! #!/bin/=&ft autocmd FileType perl,python,ruby inoremap ! #!/usr/bin/env=&ft autocmd FileType c,cpp,cs,java,perl,javscript,php,aspperl,tex,css let b:surround_101 = "\r\n}" autocmd FileType apache setlocal commentstring=#\ %s autocmd FileType aspvbs,vbnet setlocal comments=sr:'\ -,mb:'\ \ ,el:'\ \ ,:',b:rem formatoptions=crq autocmd FileType css silent! setlocal omnifunc=csscomplete#CompleteCSS autocmd FileType cucumber silent! compiler cucumber | setl makeprg=cucumber\ "%:p" | imap pumvisible() ? "\" : (CucumberComplete(1,'') >= 0 ? "\\" : (getline('.') =~ '\S' ? ' ' : "\")) autocmd FileType git,gitcommit setlocal foldmethod=syntax foldlevel=1 autocmd FileType gitcommit setlocal spell autocmd FileType gitrebase nnoremap S :Cycle autocmd FileType help setlocal ai fo+=2n | silent! setlocal nospell autocmd FileType help nnoremap q :q autocmd FileType html setlocal iskeyword+=~ autocmd FileType java silent! compiler javac | setlocal makeprg=javac\ % autocmd FileType lua includeexpr=substitute(v:fname,'\\.','/','g').'.lua' autocmd FileType mail if getline(1) =~ '^[A-Za-z-]*:\|^From ' | exe 'norm gg}' |endif|silent! setlocal spell autocmd FileType perl silent! compiler perl autocmd FileType pdf setlocal foldmethod=syntax foldlevel=1 autocmd FileType ruby setlocal tw=79 comments=:#\ isfname+=: autocmd FileType ruby \ if expand('%') =~# '_test\.rb$' | \ compiler rubyunit | setl makeprg=testrb\ \"%:p\" | \ elseif expand('%') =~# '_spec\.rb$' | \ compiler rspec | setl makeprg=rspec\ \"%:p\" | \ else | \ compiler ruby | setl makeprg=ruby\ -wc\ \"%:p\" | \ endif autocmd User Bundler if &makeprg !~ 'bundle' | setl makeprg^=bundle\ exec\ | endif autocmd FileType liquid,markdown,text,txt setlocal tw=78 linebreak nolist autocmd FileType tex silent! compiler tex | setlocal makeprg=latex\ -interaction=nonstopmode\ % formatoptions+=l autocmd FileType tex if exists("*IMAP")| \ call IMAP('{}','{}',"tex")| \ call IMAP('[]','[]',"tex")| \ call IMAP('{{','{{',"tex")| \ call IMAP('$$','$$',"tex")| \ call IMAP('^^','^^',"tex")| \ call IMAP('::','::',"tex")| \ call IMAP('`/','`/',"tex")| \ call IMAP('`"\','`"\',"tex")| \ endif autocmd FileType vbnet runtime! indent/vb.vim autocmd FileType vim setlocal keywordprg=:help nojoinspaces autocmd FileType * if exists("+omnifunc") && &omnifunc == "" | setlocal omnifunc=syntaxcomplete#Complete | endif autocmd FileType * if exists("+completefunc") && &completefunc == "" | setlocal completefunc=syntaxcomplete#Complete | endif augroup END "}}}2 endif " has("autocmd") " }}}1 " Section: Visual {{{1 " -------------------- " Switch syntax highlighting on, when the terminal has colors if (&t_Co > 2 || has("gui_running")) && has("syntax") function! s:initialize_font() if exists("&guifont") if has("mac") set guifont=Monaco:h12 elseif has("unix") if &guifont == "" set guifont=bitstream\ vera\ sans\ mono\ 10 endif elseif has("win32") set guifont=Consolas:h11,Courier\ New:h10 endif endif endfunction command! -bar -nargs=0 Bigger :let &guifont = substitute(&guifont,'\d\+$','\=submatch(0)+1','') command! -bar -nargs=0 Smaller :let &guifont = substitute(&guifont,'\d\+$','\=submatch(0)-1','') noremap :Smaller noremap :Bigger if exists("syntax_on") || exists("syntax_manual") else syntax on endif set list if !exists('g:colors_name') if filereadable(expand("~/.vim/colors/tim.vim")) colorscheme tim elseif filereadable(expand("~/.vim/colors/tpope.vim")) colorscheme tpope endif endif augroup RCVisual autocmd! autocmd VimEnter * if !has("gui_running") | set background=dark notitle noicon | endif autocmd GUIEnter * set background=light title icon cmdheight=2 lines=25 columns=80 guioptions-=T guioptions-=m guioptions-=e guioptions-=r guioptions-=L autocmd GUIEnter * if has("diff") && &diff | set columns=165 | endif autocmd GUIEnter * silent! colorscheme vividchalk autocmd GUIEnter * call s:initialize_font() autocmd GUIEnter * let $GIT_EDITOR = 'false' autocmd Syntax sh syn sync minlines=500 autocmd Syntax css syn sync minlines=50 autocmd Syntax csh hi link cshBckQuote Special | hi link cshExtVar PreProc | hi link cshSubst PreProc | hi link cshSetVariables Identifier augroup END endif " }}}1 if filereadable(expand("~/.vimrc.local")) source ~/.vimrc.local endif