Steve Hall wrote:
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()



What about this?

        redir! > version.txt
        silent version
        redir END
        new version.txt
        setlocal textwidth=70
        " remove empty lines at top
        1,/Vi IMproved/-1d
        " add empty line before /Features included/
        " MUST use single quotes, "" is Vim comment
        /Features included/-1put =''
        " put cursor on 1st +/- features lines
        norm jj
        " join all +/- features lines together
        .,/system vimrc/-1j
        " reformat features to 'textwidth'
        norm gqq
        " add empty line between +/- features and /system vimrc/
        put =''
        " add empty line before /Compilation/
        /^Compilation:/-1put =''
        " reformat Compilation line
        norm jgqq
        " add empty line before /Linking/
        put =''
        " reformat Linking line
        norm jgqq
        " save
        wq

I just tested it. It will write (as version.txt in the current directory, overwritten if existing) the "beautified" text ready for upload to your "Release Notes" page on sourceforge. (I think it won't work on Tiny and Small builds.) ;-)

Just paste the above code as a script (e.g. ~/.build/vim/vim70/beautyversion.vim). If you replace "new" by "edit" at line 4, you can (IIUC) use something like

version.txt: src/gvim.exe
        src/gvim -u NONE -i NONE -N -S beautyversion.vim

as a makefile rule to produce the beautified text in batch mode.


Best regards,
Tony.

Reply via email to