[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 13:20:26 +0100 |
On Tue, 26 Jan 2021 03:51:01 +0000 Greg Chicares <gchicares@sbcglobal.net>
wrote:
GC> On 1/26/21 12:12 AM, Vadim Zeitlin wrote:
[...]
GC> > GC> What am I misunderstanding?
GC> >
GC> > As I said, I don't use visual mode often, but it looks like \%V is meant
GC> > to work like this, at least the example for it in the help says:
GC> >
GC> > [...] To make sure the whole pattern is
GC> > inside the Visual area put it at the start and just before the end of
GC> > the pattern, e.g.: >
GC> > /\%Vfoo.*ba\%Vr
GC>
GC> Wait...compare the online documentation [but see below]:
GC>
GC> http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\%V
Generally speaking, I'd consider anything with "sourceforge.net" in the
URL outdated by default in 2021.
GC> | [...] To make sure the whole pattern is
GC> | inside the Visual area put it at the start and end of the pattern,
GC> | e.g.:
GC> | /\%Vfoo.*bar\%V
GC>
GC> What you quoted seems to describe the behavior I'm seeing,
GC> whereas the online documentation describes what I want.
GC>
GC> Of course, I was imagining that that online documentation was
GC> the latest; but it says:
GC> | *pattern.txt* For Vim version 7.3. Last change: 2011 Feb 25
GC> so I guess you quoted a corrected version.
Sorry, I should have mentioned that I was using 8.2, but I didn't think
the behaviour of something like this could depend on the version. Of
course, the behaviour actually didn't change, but the documentation did.
GC> I'll try to remember to use this instead:
GC>
GC> https://vimhelp.org/
GC> | For Vim version 8.2. Last change: 2020 Aug 15
GC>
GC> which gives yet another, different explanation:
GC> https://vimhelp.org/pattern.txt.html#%2F%5C%25V
GC> | [...] To make sure the whole pattern is
GC> | inside the Visual area put it at the start and just before the end
of
GC> | the pattern, e.g.:
GC> | /\%Vfoo.*ba\%Vr
GC> | This also works if only "foo bar" was Visually selected. This:
GC> | /\%Vfoo.*bar\%V
GC> | would match "foo bar" if the Visual selection continues after the
"r".
GC>
GC> > so it explicitly says to use "/\%V.*\%V./" in your case. I have no good
GC> > explanation for this behaviour, but I think I at least have a slightly
less
GC> > counterintuitive workaround: you could also use "/\(\%V.\)\+/" which I
read
GC> > as "match any sequence of characters inside the visual area".
GC>
GC> OK, thanks. It just seems crazy to me, but the maintainers know
GC> about it:
GC>
GC> https://groups.google.com/g/vim_dev/c/l8uTRc43ETI/m/H6KN6YopFhMJ
This also explains why it works like this: "\%V" matches before the last
selection character but not after it because it's already outside of the
selection. I also really like the idea of "\%<V" mentioned in that thread,
but unfortunately this doesn't seem to have been pursued further (hard to
be sure because searching for "\%<V" is difficult).
Regards,
VZ
pgpXTVhgcmcp5.pgp
Description: PGP signature