Tim Chase<v...@tim.thechases.com> a écrit:
> On 2013-06-09 20:37, meino.cra...@gmx.de wrote:
> > Paul Isambert <zappathus...@free.fr> [13-06-09 20:28]:
> > > I’m not sure I understand you correctly, but perhaps the following
> >> will help:
> >> 
> >>     function! s:bars ()
> [snip]
> >>     endfunction
> >>     com! -buffer Bars call s:bars()
> >> 
> >> |            |   |          | abcde | |
> >> produces:
> >> |            |   |          | abcde | |
> >> 0            12  3          10      7 1
> > 
> > yes,yes,yes,!!! Exactly what I want! THANKS A LOT! You helped me
> > more as you may think :) ! Great help! 8)
> ...
> >> (I’m sure there’s a Vim wizard out there who can do all that with
> >> only “:substitute”.)
> 
> Though just a first pass, since Paul threw down the challenge:
> 
>  :s/.*/\=submatch(0)."\n".(join(map(split(submatch(0), '|', 1),
>  'printf("%".strlen(v:val)."s", strlen(v:val))')))/g
> 
> gives a pretty close approximation to his solution as a
> one-line :substitute command. Differences I notice:
> 
> 1) it has one extra 0-width field listed at the end which shows the
> width of the last column (in Paul's sample input, it was zero-width,
> but if there were additional characters, it would list how wide the
> field was)
> 
> 2) it right-justifies the number with the pipe rather than
> left-justifying it.
> 
> So on Paul's example, I get
> 
>   |            |   |          | abcde | |
>   0           12   3         10       7 1 0

The following is, I hope, an improvement: it removes the trailing zero
and fixes cases when the line doesn’t begin with a pipe. The best part
of it, though, is the the “nohl” at the end :)

:s/.*/\=submatch(0)."\n".substitute(join(map(split(submatch(0), '|', 1), 
'printf("%".(strlen(v:val)+1)."s", strlen(v:val))'), ''), '\s*0$', '', '')/g | 
nohl

Best,
Paul

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to