Reformat tabular test data ending with a lengthy description onto multiple tabulated lines

8 views
Skip to first unread message

Graham Lawrence

unread,
Dec 14, 2015, 3:28:11 PM12/14/15
to vim...@googlegroups.com
 
Here is my test data
Example 1     Of medium length     Enough words in description 
to need one reformat Example 2 Very short one Needs no reformat Example 3 Extremely long one This description is long
enough and drivels on and on pointlessly for no other purpose
than to trigger multiple reformatted lines. Here are the :s commands which produced the best results so far and show exactly what I'm trying to achieve :'a,'b-1s/.\{66,}/\=substitute(submatch(0),'\(.\{35}\)\(.\{,30}\) \(\(.\{,30}\)[ \n]\)\+','\1\2\r@@\1\3','')/g :'a,'b-1s/^@@\(.\{35}\)/\=substitute(submatch(1),'.',' ','g') Here is what they do to my test data Example 1 Of medium length Enough words in description to need one reformat Example 2 Very short one Needs no reformat Example 3 Extremely long one This description is long multiple reformatted lines. So, it loses the interior lines of a multiple reformat. To get
those I revisualized the structure of these lines thus: \(.\{35}\)\(.\{,30}\)\( .\{,30}\)\+ and that all I really needed to do is replace that leading
space in each of the repeated third fields with \r@@\1, ie
that my first :s should be something like :'a,'b-1s/.\{66,}/\=substitute(submatch(0),'\(.\{35}\)\(.\{,30}\)\( .\{,30}\)\+', "\=substitute(submatch(3), '^ ', '\r@@\1', '')", 'g') which produced this output =substitute(submatch(3), '^ ', ' @@ ', '') Example 2 Very short one Needs no reformat =substitute(submatch(3), '^ ', ' @@ ', '')=substitute(submatch(3), '^ ', ' @@ ', '') which I read as the second \=expression is not being treated
as such, but no variations like doubling the \ to cater for
the enclosing "s makes any difference. Advice as to how to
proceed, please.


--
Graham Lawrence
Reply all
Reply to author
Forward
0 new messages