" use custom indenting otherwise just guess if has("filetype") filetype on filetype plugin indent on else if has("smartindent") set smartindent endif endif " new file? fill it with a skeleton function! InitNewFile(type) if a:type == "py" execute setline(1, "#!/usr/bin/env python3") elseif a:type == "rb" execute setline(1, "#!/usr/bin/env ruby") elseif a:type == "pl" execute setline(1, ["#!/usr/bin/env perl", "use warnings;", "use strict;"]) elseif a:type == "sh" execute setline(1, "#!/bin/bash") elseif a:type == "scm" execute setline(1, ["#!/usr/bin/scsh -s", "!#"]) endif normal Go startinsert endfunction function! CamlCommentLine() if getline(".") =~ '(\*' execute 's/(\*//' execute 's/\*)//' echo "uncommented!" else execute 's/^/(*/' execute 's/$/*)/' echo "commented!" endif endfunction function! RCommentLine() if getline(".") =~ '^#! ' execute 's/^#! //' else execute 's/^/#! /' endif endfunction function! RCommentPara() let lno = line(".") let start = search("^$", 'b') + 1 let end = search("^$") while (start < end) exe start call RCommentLine() let start = start + 1 endwhile exe lno endfunction " empty autocmd and re-fill if has("autocmd") " start new group and zorch the old autocmds augroup every_file autocmd! " jump to the last cursor position autocmd BufReadPost * normal g`" " cd to dir of file autocmd BufEnter * cd %:p:h " complete at least local buffer autocmd BufEnter * setlocal complete=. autocmd BufEnter * match Error /^ \+\|^\t\+ \+/ augroup END " common to all scripts augroup scripts_common autocmd! autocmd BufWritePost *.{sh,scm,pl,p6,tcl,cgi,py,py3,ml} silent execute ":!chmod +x " autocmd FileType perl,pm,lisp,scheme,tcl,python,c setlocal formatoptions=tcqr autocmd FileType perl,pm,lisp,scheme,tcl,python,c setlocal ff=unix autocmd FileType perl,pm,lisp,scheme,tcl,python,c setlocal listchars=tab:+-,trail:@ augroup END augroup r_stats autocmd! autocmd BufEnter *.r nnoremap C :call RCommentPara() autocmd BufEnter *.r nnoremap c :call RCommentLine() augroup END " python augroup python autocmd! autocmd BufNewFile *.py call InitNewFile("py") autocmd BufEnter *.py syntax on autocmd BufEnter *.py setlocal ft=python autocmd FileType python setlocal keywordprg=pydoc autocmd FileType python setlocal iskeyword+=. autocmd FileType python setlocal sw=4 ts=4 expandtab list autocmd FileType python setlocal listchars=tab:+-,trail:@ autocmd BufEnter *.py match Error /^ \+\t\+\|^\t\+ \+\| \+$/ autocmd BufReadPost *.py retab ! augroup END " perl augroup perl autocmd! autocmd BufNewFile *.{pl,pm,p6} call InitNewFile("pl") autocmd Syntax *.{pl} syn match Error /^ \+/ autocmd FileType perl,pm setlocal keywordprg=perldoc\ -f autocmd FileType perl,pm setlocal iskeyword+=: augroup END " ruby augroup ruby autocmd! autocmd BufNewFile *.rb call InitNewFile("rb") autocmd BufEnter *.rb setlocal sw=2 expandtab list listchars=tab:+- autocmd BufEnter *.rhtml setlocal sw=4 noexpandtab list listchars=tab:+- autocmd BufEnter *.rb match Error /^ \+\t\+\|^\t\+ \+\| \+$/ augroup END " scheme augroup scheme autocmd! autocmd BufNewFile *.scm call InitNewFile("scm") augroup END " ocaml augroup ocaml autocmd! autocmd BufEnter *.ml setlocal ft=ocaml et autocmd BufEnter *.ml nnoremap c :call CamlCommentLine() autocmd BufEnter *.ml nnoremap C {:s/^/(*/}:s/$/*)/ autocmd BufEnter *.ml match Error /^\t\+\|^\t\+ \+\|^ \+$/ augroup END " c augroup c_code autocmd! autocmd BufEnter *.{c,h} setlocal listchars=tab:+- autocmd BufEnter *.{c,h} match Error /^ \+\|^\t\+ \+/ augroup END " shell scripts augroup shell_scripts autocmd! autocmd BufNewFile *.sh call InitNewFile("sh") autocmd BufEnter *.sh set si autocmd BufEnter *.sh set iskeyword+=. augroup END " rebuild vim and help tips automatically augroup vim_help autocmd! autocmd BufWritePost *.vim,*vimrc source % autocmd BufWritePost */etc/vim/doc/*.txt helptags ~/etc/vim/doc/ autocmd BufRead */etc/vim/doc/*.txt setlocal filetype=helpfile noreadonly modifiable augroup END " email augroup email autocmd! autocmd BufRead,BufNewFile /tmp/mutt* :set ft=mail autocmd BufRead,BufNewFile /Private/*/mutt* :set ft=mail autocmd FileType mail setlocal tw=72 formatoptions=tcql nosi autocmd FileType mail setlocal comments=b:>,b:Attach\:,b:From\:,b:To\:,b:Bcc\:,b:Cc\:,b:Bcc\:,b:Subject\:,b:Reply-To\:,b:In-Reply-To\: autocmd FileType mail let g:autoformat_mode = 1 augroup END " make augroup make autocmd! autocmd FileType make setlocal noexpandtab augroup END " xml augroup xml autocmd! autocmd FileType xml setlocal noexpandtab sw=4 ts=4 augroup END " tex augroup tex autocmd! autocmd FileType plaintex setlocal makeprg=make\ %:t:r.pdf augroup END " :make edit/compile/debug easier if has("quickfix") augroup makeprogram autocmd FileType c setlocal makeprg=gcc\ -Wall\ -ggdb\ -o\ %<\ % autocmd FileType perl,pm setlocal makeprg=perl\ % autocmd FileType perl,pm setlocal errorformat+=%m\ at\ %f\ line\ %l. autocmd FileType python setlocal makeprg=python\ % autocmd FileType python setlocal errorformat=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m "autocmd FileType python setlocal errorformat=File\ "%f",\ line\ %l autocmd FileType scheme,scm,scsh setlocal makeprg=bash\ -c\ ./% autocmd FileType ruby,rb setlocal makeprg=ruby\ % augroup END endif else endif