>> 1) bring the "country ___" line down to each non-country line:
>>
>>    :v/^country /?country ?t-|s/country //|j
>> [...]
>> Step #1 is a bit packed:
>>
>>    :v/          on every line that doesn't match
>>    country      the literal text "country "
>>    /            perform this set of actions:
>>      ?country ?   look backwards to the most recent
>>                   line containing "country "
> 
> I think i don't understand this: why do you look *backward* for an occurence 
> of
> "country" after you find a line that doesn't contain "country"?

Tarlika already answered this (something like "because the 
germane country-code is above instead of below"), but skipped the 
2nd half (even though it's reasoning falls from her answer)

>>      t            and copy it
>>      -            to the line before this match
>>                   ("-" is short-hand for ".-1")
> 
> and why do you do this instead of simply deleting *country* in place?

When you have a "country" line, you don't know how many 
non-country lines will follow it, so you have to keep it around 
for any further copying-to-subsequent-non-country-lines.  So from 
her (tweaked by adding Bonn and completing the GER output 
section) example:

country GB
London
Birmingham
country GER
Berlin
Bonn
-->
GB London
GB Birmingham
GER Berlin
GER Bonn

It finds London, then copies the "country GB" line before it, 
deletes the word "country" and then joins "GB" and "London" to 
make "GB London".  It then finds Birmingham which also needs to 
copy down the previous "country" line and perform the same 
sequence of operations.  If we had deleted it in-place, it 
wouldn't be there to copy down.  If we had moved it instead of 
deleting it, then we would undo the work we did to put it befor 
London.  The alternative would still be two passes but something like

  1)   for each "country" line, join it with the next one and 
delete "country "

   :g/^country /j|s/country /

  2)  for each harder-to-identify-non-country-line (harder 
because we no longer have "country" on the line to identify 
Birmingham and Bonn), copy down the country code from some 
harder-to-identify-country-line.

   :g/magic-regexp/magic-ex-commands



Hope this helps shed some light on my thought-process :)

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to