lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] On matching the zero-width vim atom "%V"


From: Greg Chicares
Subject: Re: [lmi] On matching the zero-width vim atom "%V"
Date: Tue, 26 Jan 2021 03:51:01 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

On 1/26/21 12:12 AM, Vadim Zeitlin wrote:
> On Mon, 25 Jan 2021 21:55:21 +0000 Greg Chicares <gchicares@sbcglobal.net> 
> wrote:
> 
> GC> Here's something that I think should work, but doesn't.
> GC> 
> GC> Goal: in this line:
> GC>   InvariantValues().TermSpecAmt[j] = TermSpecAmt;
> GC> I want to call dblize() on the RHS, making it this:
> GC>   InvariantValues().TermSpecAmt[j] = dblize(TermSpecAmt);
> 
>  I know you didn't ask for this, but FWIW here is how I'd do it:
> 
> 1. Put the cursor anywhere on TermSpecAmt.
> 2. Do "s/<C-R><C-W>/dblize(&)".

Thanks, I didn't know about <C-R><C-W>.

> GC> Technique: visually highlight the string to be replaced,
> GC> e.g. with this sequence of commands on that line:
> GC>   $FTvt;
> GC> and then perform the substitution:
> GC>   :'<,'>s/\%V.*\%V/dblize(&)/
> GC> (The "$FT" part is written to make the command easy to
> GC> reproduce--it's not the way I'd normally begin a selection.)
> 
>  Another unsolicited advice: I find the fastest way to make such a
> selection is by using "viw" or similar.

Yes, but I gave an overly simplified example--the expressions
I wanted to dblize were often like these:

        dblize(DBReflectingCorr + TermDB)
        dblize(TotalAccountValue())

so "viw" or <C-R><C-W> aren't enough--something like "%V" is needed.

> GC> What am I misunderstanding?
> 
>  As I said, I don't use visual mode often, but it looks like \%V is meant
> to work like this, at least the example for it in the help says:
> 
>       [...] To make sure the whole pattern is
>       inside the Visual area put it at the start and just before the end of
>       the pattern, e.g.: >
>               /\%Vfoo.*ba\%Vr

Wait...compare the online documentation [but see below]:

  http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\%V
|       [...] To make sure the whole pattern is
|       inside the Visual area put it at the start and end of the pattern,
|       e.g.:
|               /\%Vfoo.*bar\%V

What you quoted seems to describe the behavior I'm seeing,
whereas the online documentation describes what I want.

Of course, I was imagining that that online documentation was
the latest; but it says:
|  *pattern.txt*   For Vim version 7.3.  Last change: 2011 Feb 25
so I guess you quoted a corrected version.

I'll try to remember to use this instead:

  https://vimhelp.org/
| For Vim version 8.2.  Last change: 2020 Aug 15

which gives yet another, different explanation:
  https://vimhelp.org/pattern.txt.html#%2F%5C%25V
|        [...] To make sure the whole pattern is
|        inside the Visual area put it at the start and just before the end of
|        the pattern, e.g.: 
|                /\%Vfoo.*ba\%Vr
|       This also works if only "foo bar" was Visually selected. This: 
|                /\%Vfoo.*bar\%V
|       would match "foo bar" if the Visual selection continues after the "r".

> so it explicitly says to use "/\%V.*\%V./" in your case. I have no good
> explanation for this behaviour, but I think I at least have a slightly less
> counterintuitive workaround: you could also use "/\(\%V.\)\+/" which I read
> as "match any sequence of characters inside the visual area".

OK, thanks. It just seems crazy to me, but the maintainers know
about it:

https://groups.google.com/g/vim_dev/c/l8uTRc43ETI/m/H6KN6YopFhMJ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]