Tuesday, September 24, 2013

Re: Using back-references in 'range'

-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iF4EAREIAAYFAlJBuwYACgkQRL8D6wymVNYY+AD8CwFFBoEhLAW+G7b7lu8A+/gK
wURyOZy8WreFmG7S+dEA/AgI2J7275M2oBS0cjf2H1htxLAgtYIohC7iDiuu6SRC
=896L
-----END PGP SIGNATURE-----
On 23 Sep 2013, at 19:44, Ben Fritz wrote:
> On Monday, September 23, 2013 11:54:27 AM UTC-5, Andrew Long wrote:
>>
>> What I thought of was to use a global operation limited to the 'for' and the matching 'repeat', and what I tried was this:-
>>
>>
>>
>> :/^\(\s\+\)for\s\+\(\a\k*\)\s\+to.*/,/^\1repeat/g/\2/s/\2/i/g
>>
>>
>>
>> Only I fell at the first hurdle because it fails to find the matching repeat pattern.
>>
>
> In Vim, you can only ever use a backreference in the search where it was created. You cannot re-use a backreference from an earlier search in a later search.
>
> Here you have 4 searches. You use two for a range, one for the :g command, and another for the :s command.
>
> Only backreferences defined in the search pattern for the :s command can be used in the search or replace pattern for that command. You cannot use backreferences from the line range searching.
>
> Only backreferences defined in the pattern for the :g command can be used later in that pattern, you cannot use backreferences from the line range searching.
>
> Only backreferences defined in the "to" line pattern can be used in that pattern, you cannot use the backreference from the "from" line.

OK, thanks for that explanation Ben. Just ahve to try harder to find a different solution

Regards, Andy


--
Andrew Long
andrew dot long at mac dot com

No comments:

Post a Comment