René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

EmbedVisualSelection [Vim Script]

function! EmbedVisualSelection(txt_before, txt_after)

  let l:area = VisualBlockBoundaries()

" Append after end of visual selection
  call setpos(".", [0, l:area.line_e, l:area.col_e, 0])
  execute "normal a" . a:txt_after . nr2char(27)

" Insert befor beginning of visual selection
" TODO: create SetPos with 0-based semantics
  call setpos(".", [0, l:area.line_b+1, l:area.col_b+1, 0])
  execute "normal i" . a:txt_before . nr2char(27)

endfu

If EmbedVisualSelection is called from another function that in turn is called from the command prompt, that other function should have the range modifier:
function! E() range
  
  call EmbedVisualSelection("<span class='e'>", "</span>")

endfunction
See also other Vim scripts.