From: Tim Chase, Wed, October 18, 2006 6:46 am
>
> > 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
  function! Version()
      redir @x
      silent! version
      redir END
      " add some line breaks between major sections
      let @x = substitute(@x, '\n\([+\-]arabic\)', '\n\n\1', '')
      let @x = substitute(@x, '\n\(\s\+system\)', '\n\n\1', '')
      let @x = substitute(@x, '\n\(Compilation\)', '\n\n\1', '')
      let @x = substitute(@x, '\n\(Linking\)', '\n\n\1', '')
      " wrap
      echo Str_wrap(@x, 70)
  endfunction
  command! Version call Version()


-- 
Steve Hall  [ digitect dancingpaper com ]

Reply via email to