<<< Date Index >>>     <<< Thread Index >>>

Re: vim and mutt [WAS: Re: Encoding Japanese Characters in a totally English environment]



Thomas Glanzmann (2004-07-30, 11:10):
> > Last but not least, become acquainted with your editor of choice.
> > Vim[4] is your friend ;-)
> 
> true.

Dead sure!

,----[ $HOME/etc/vim/modes/mail.vim ]
| " Some settings for writing mail with mutt and news with slrn
| " this file is sourced by autocommands.vim if necessary
|
| " Signature mappings:
| " ,s - select (another) random signature
| " ,d - remove signature
| " ,a - select a signature (opens a new buffer, use <CR> to select sig)
|
| " All signatures must be placed in a textfile. Each signature seperated by 
| " a line only containing '-- '
| let s:signature_file = '$HOME/etc/mail/signatures/signature.db'
|
| if ! exists( "*HasSig" )
|
|     function HasSig()
|       let lnum = line(".")
|       let cnum = col(".")
|       normal! H
|       let scrtop = line(".")
|       let hasSig = 0
|       normal! G
|       let botl = line(".")
|       let sigstart = search( "^-- $", "bW" )
|       if sigstart != 0 && botl - sigstart <= 4
|           let hasSig = 1
|       endif
|       call cursor( scrtop, 0 )
|       normal! zt
|       call cursor( lnum, cnum )
|       return hasSig
|     endfun
|
|     function ChooseSig()
|       let s:choose_sig_lnum = line(".")
|       let s:choose_sig_cnum = col(".")
|       normal! H
|       let s:choose_sig_scrtop = line(".")
|       let s:choose_sig_mailbuffer = bufnr("%")
|       " open signaturedb readonly
|       execute "new ".s:signature_file
|       set readonly
|       " map <CR> to exchange current signature with selected
|       map <CR> :silent call ChooseSig2()<CR>
|     endfun
|
|     function ChooseSig2()
|       let lnum = line(".")
|       bdelete
|       execute 'buffer ' . s:choose_sig_mailbuffer
|       call InsertSig( lnum )
|       call cursor( s:choose_sig_scrtop, 0 )
|       normal! zt
|       call cursor( s:choose_sig_lnum, s:choose_sig_cnum )
|     endfun
|
|     function InsertSig( ... )
|       let modified=&modified
|       if modified == 1
|           write
|       endif
|       let lnum = line(".")
|       let cnum = col(".")
|       normal! H
|       let scrtop = line(".")
|       execute "view ".s:signature_file
|       if ! exists( 's:sigline' )
|           " helper to choose different signatures within one second
|           " FIXME need real random
|           let s:sigline = 0
|       endif
|       if a:0 == 0
|           normal! G
|           " FIXME is there really no random function in vim???
|           let s:sigline = ( s:sigline + localtime() ) % line(".")
|       else
|           let s:sigline = a:1
|       endif
|       execute s:sigline
|       execute '?^-- $?;/^-- $/-y'
|       execute 'bdelete'
|       normal! G
|       normal! p 
|       call cursor( scrtop, 0 )
|       normal! zt
|       call cursor( lnum, cnum )
|       if modified == 0
|           set nomodified
|       endif
|     endfun
|
|     function DelSig()
|       let modified=&modified
|       let lnum = line(".")
|       let cnum = col(".")
|       normal! H
|       let scrtop = line(".")
|       normal! G
|       execute '?-- $?,$d'
|       call cursor( scrtop, 0 )
|       normal! zt
|       call cursor( lnum, cnum )
|       if modified == 0
|           set nomodified
|       endif
|     endfun
|
|     function NextSig()
|       if HasSig() == 1
|           call DelSig()
|       endif
|       call InsertSig()
|     endfun
|
|     nnoremap ,s :silent call NextSig()<CR>
|     nnoremap ,d :silent call DelSig()<CR>
|     nnoremap ,a :silent call ChooseSig()<CR>
|
|     set list
|     set listchars=trail:_,tab:>.
|     set expandtab
|     set textwidth=64
|     set comments=nb:>
|     set noshowmatch
|     abbr hm Hendrik
|     if ! HasSig()
|       silent call InsertSig()
|     endif
|     normal! gg
|     "execute '/^Subject:/'
|     execute "normal! f: "
|
| endif
`----

Hendrik