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

EnsureStringLength [Vim Script]

Returns txt, making sure, that the length of txt is at least len characters. If its length is shorter, it will be right padded with blank characters.
function! EnsureStringLength(txt, len)

  let l:len = strlen(a:txt)

  if l:len > a:len
    return a:txt
  endif

  let l:chars_left = a:len - l:len

  let l:result = a:txt
  while l:chars_left > 0 
    let l:result = l:result . ' '
    let l:chars_left = l:chars_left - 1
  endwhile

  return l:result

endfunction
See also other Vim scripts.