I'm having a mental block, how can I wrap a string via
substitute() ?
The following seems to do the trick for me:

  echo substitute(str, '[[:print:]]\{,10}', '&\n', 'g')

This nearly works, but is doubling existing line breaks.

The application is this :version pretty-fier:

  function! Str_wrap(str, len)
    return substitute(a:str, '[[:print:]]\{,'.a:len.'}','&\n','g')
  endfunction

I must be missing something...in your original post, you didn't have any linebreaks in your sample str...thus my answer didn't deal with them. ;)

If you have a multi-line string and want to do a wrapping as something sorta like "gqip" would do (minus its internal smartness about things like comment-leaders or mail-quote characters),


echo substitute(@", '\([[:print:]]\{,10}\)\>[^[:cntrl:]]', '&\n', 'g')

seems to do something fairly reasonably kinda sorta close to what I understand you to be describing. :)

-tim




Reply via email to