[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] On matching the zero-width vim atom "%V"
From: |
Vadim Zeitlin |
Subject: |
Re: [lmi] On matching the zero-width vim atom "%V" |
Date: |
Tue, 26 Jan 2021 01:12:26 +0100 |
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(&)".
This might not be the optimal way to do it from the key stroke count
point of view but I find it more convenient than using visual mode (but, in
the interest of full disclosure, I'm cognizant of the fact that I don't use
visual mode enough and should use it more because some things are really
better done with it).
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.
GC> That fails, yielding:
GC> InvariantValues().TermSpecAmt[j] = dblize(TermSpecAm)t;
GC>
GC> It works if I highlight one more character ('f', not 't'):
GC> $FTvf;
GC> :'<,'>s/\%V.*\%V/dblize(&)/
GC> InvariantValues().TermSpecAmt[j] = dblize(TermSpecAmt);
GC> But earlier I excluded that terminal ';' from the selection
GC> because I don't want to operate on it--I don't want
GC> InvariantValues().TermSpecAmt[j] = dblize(TermSpecAmt;)
GC> which is what I would expect when highlighting includes ';'.
GC>
GC> Similarly, if the string to be replaced extends to EOL:
GC> ,NetPmts[Month]
GC> then "$FNvg_" highlights the string I want to replace,
GC> but to use the "s" command above I must instead highlight
GC> it with "$FNv$", which, jarringly, extends the selection
GC> for two (not one) pseudo characters past the end.
GC>
GC> (I don't think this is caused by any unusual vim setting,
GC> but lmi's 'gwc/.vimrc' gives my full configuration).
I can confirm that I can reproduce this behaviour and that I see it even
with "vim -u NONE".
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
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".
Regards,
VZ
pgpl820v1ZO_b.pgp
Description: PGP signature