Tuesday, March 21, 2017

Re: Can I include /range/ in substitute pattern?

Hi Jakykong,

love the name :)

(I was a big Kong fan in my time)

I think I wasn't explaining myself clearly.

Also I was a bit confused.

What I was trying to do was this: (AutoIt3 BASIC)

=====
Dim $K_MAINGUIWIDTH

$K_MAINGUIWIDTH = 320

..

GUICreate( "hello world!", 200, 100 ........
=====
say I'm interested in that string $K_MAINGUIWIDTH right at the top there

it's a GUI in AutoIt3

I was looking change the GUICreate to use $K_MAINGUIWIDTH instead of a set 200

I got confused because /RANGE/ and s// are different. The
/RANGE/s//NEW TEXT/ is a special case where Vim lets you use the
previously used pattern as the search pattern in the s//

In fact my replacement can be achieved in s// exclusively

you do:
1s/\(\_.\{-}\)\($K_MAINGUIWIDTH\)\(\_.\{-}\)200/\1\2\3\2/

ask Vim to go skip through the entire fie
\_.\{-}
until it matches $K_MAINGUIWIDTH
then keep going
\_.\{-}
until you match 200

then your substitute string you just put those things back
\1\2\3
then add your desired string
\2

Works for me!

Cheers, Pablo.



On 3/21/17, jakykong@theanythingbox.com <jakykong@theanythingbox.com> wrote:
> On Tuesday, March 14, 2017 at 10:28:23 AM UTC-7, Pablo Contreras wrote:
>
>>
>> my previous trick:
>>
>> :/kites/s//...... /
>>
>> doesn't work here because I'm trying to match both 'kites' and 'and
>> bikes'
>>
>> Is this too ambitious?
>>
>> Thanks in advance! Pablo.
>
> If you had searched /kites/ first, I'd suggest <C-r>/ to paste the search
> register, but clearly that isn't what you're after. If you do it that way,
>
> /kites
> :s/\(<C-r>/\)\(.*\)\(bikes\)/\3\2\1/
>
> would shorthand typing kites (Just in case I'm not being clear about the key
> sequence here, <C-r>/ means ctrl+r then '/', and these are two commands, one
> to search and one to substitute)
>
> That works for your example on my machine.
>
>
> --
> --
> 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 a topic in the
> Google Groups "vim_use" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/vim_use/wKhhteq8SKI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: