setlocal textwidth=68 setlocal formatoptions-=o setlocal formatoptions-=r " for format_flowed "setlocal formatoptions+=aw "setlocal nolist "augroup listinsert " autocmd! "augroup end "augroup tsperrorinsert " autocmd! "augroup end "setlocal spell " Dynamically set format options, depending on where you are in a " mail, idea from Teemu Likonen: " http://groups.google.com/group/vim_use/msg/f59e5c1adc6be2b3 let d_fo = &fo let s:defaults = 'setlocal tw=68 ts=2 sts=2 sw=2 fo='.d_fo execute s:defaults let b:MailAreaDetect=1 "nnoremap ma1 :call MailAreaDetect_On() " \ echo 'MailAreaDetect On' "nnoremap ma0 :call MailAreaDetect_Off() " \ echo 'MailAreaDetect Off' nnoremap :call MailAreaDetect_Switch(0) inoremap :call MailAreaDetect_Switch(1) function! s:MailAreaDetect_Switch(vmode) if b:MailAreaDetect silent call MailAreaDetect_Off() let b:MailAreaDetect=0 echo 'MailAreaDetect Off' if a:vmode sleep 1 endif else silent call MailAreaDetect_On() let b:MailAreaDetect=1 echo 'MailAreaDetect On' if a:vmode sleep 1 endif endif endfu function! s:MailAreaDetect_On() silent autocmd! MailAreaDetect CursorMoved,CursorMoved \ call AreaOptions() let b:MailAreaDetect=1 endfunction function! s:MailAreaDetect_Off() silent autocmd! MailAreaDetect execute s:defaults let b:MailAreaDetect=0 endfunction augroup MailAreaDetect autocmd! call MailAreaDetect_On() augroup END function! s:AreaOptions() execute s:defaults if CheckArea('\v^From( |: ).*\n','\v^$') "echo 'Header' setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet elseif getline('.') =~ '\m^\s*>' "echo 'Quotation' setlocal fo-=a fo-=w elseif CheckArea('\m^--- .*\n^+++ ','\v(^$|\n^-- $)') "echo 'Patch' setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet elseif CheckArea('^-- $','^$') "echo 'Signature' setlocal fo-=a fo-=w fo-=t sts=0 sw=2 noet else "echo 'My text' setlocal fo+=aw et endif endfunction function! s:CheckArea(start, end) return (search(a:start,'bcnW')-line('.')) > \ (search(a:end,'bnW')-line('.')) endfunction augroup tsperrorinsert au! augroup END match none /\s\+$/ augroup listinsert au! augroup END set nolist