VIM: How to pad string with spaces in function? - SOLUTION

editor

    Next

  • 1. vim: Calling function in line selection mode
    Hi, I've written a function which works fine on one line. What would be the easiest way to enable it to work on all lines which I've selected in line selection mode ? -- Luka
  • 2. how to redirect vim internal command output to the current buffer?
    Hi, I want to save the output of same vim commands, such as :reg and :version, to the current buffer, but it seems that only external commands can be redirected in the way :r !ls, I can not run :r version or :r :version. Can anyone please tell me how to do? Thanks! -- Jerry

Re: VIM: How to pad string with spaces in function? - SOLUTION

Postby James Egan » Thu, 26 Oct 2006 12:41:42 GMT




Thanks!  Using the repeat command, here is the solution
I've implemented:


function! MySpam()

  let ip=input("Enter IP address or domain name: ")

  if (ip != "")
    let col = 30
    let rej = 'REJECT "550 SPAMMER NINCOMPOOP REJECTED!!!'
    let iplen = len(ip)
    let padding = col - len(ip)
    let padding =  ip.repeat(' ', padding).rej

    call append( line("."), padding)
    call cursor(line(".")+1, 1)
  endif

endfunction




Return to editor

 

Who is online

Users browsing this forum: No registered users and 1 guest