gv bug?

25 views
Skip to first unread message

Tim Chase

unread,
Jul 19, 2020, 9:24:46 AM7/19/20
to v...@vim.org
To replicate

$ vi -u NONE
:r !jot 15

(or use `seq 15` to get the numbers 1-15 in your file)

3GVG:g/5/d

This should delete lines 5 and 15 because they contain a "5".
However, issueing

gv

does not reselect the text. If instead you have 16 numbers

$ vim -u NONE
:r !jot 16

and do

3GVGk:g/5/d

(selecting through the penultimate line, so the same text selected
as before, followed by the same command, just with a line below '>
containing "16") followed by

gv

it works, adjusting the '> mark to the line containing "16". So
there's clearly some "the last line of my visual range was deleted,
so we need to adjust it" logic, but it doesn't seem to check if that
adjusment runs of the end of the file and back it off instead.

Thanks!

-tim

(brought to my attention in this thread
https://www.reddit.com/r/vim/comments/htfc78/vimscript_deletion_inside_visual_selection/
where it caused some odd edge-cases)


Bram Moolenaar

unread,
Jul 19, 2020, 11:18:22 AM7/19/20
to vim...@googlegroups.com, Tim Chase, v...@vim.org

Tim Chase wrote:

> To replicate
>
> $ vi -u NONE
> :r !jot 15
>
> (or use `seq 15` to get the numbers 1-15 in your file)
>
> 3GVG:g/5/d
>
> This should delete lines 5 and 15 because they contain a "5".
> However, issueing
>
> gv
>
> does not reselect the text.

For me it does. I cannot guess why it doesn't work for you.

> If instead you have 16 numbers
>
> $ vim -u NONE
> :r !jot 16
>
> and do
>
> 3GVGk:g/5/d
>
> (selecting through the penultimate line, so the same text selected
> as before, followed by the same command, just with a line below '>
> containing "16") followed by
>
> gv
>
> it works, adjusting the '> mark to the line containing "16". So
> there's clearly some "the last line of my visual range was deleted,
> so we need to adjust it" logic, but it doesn't seem to check if that
> adjusment runs of the end of the file and back it off instead.
>
> Thanks!

--
It was recently discovered that research causes cancer in rats.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Tim Chase

unread,
Jul 19, 2020, 2:54:15 PM7/19/20
to Bram Moolenaar, vim...@googlegroups.com, v...@vim.org
On 2020-07-19 17:18, Bram Moolenaar wrote:
> Tim Chase wrote:
> > To replicate
> >
> > $ vi -u NONE
> > :r !jot 15
> >
> > (or use `seq 15` to get the numbers 1-15 in your file)
> >
> > 3GVG:g/5/d
> >
> > This should delete lines 5 and 15 because they contain a "5".
> > However, issueing
> >
> > gv
> >
> > does not reselect the text.
>
> For me it does. I cannot guess why it doesn't work for you.

I just went to reproduce it and there seems to be something to the
order of how the lines are selected. I slightly tweaked the order of
the commands to make it clear what range I was selecting, assuming
that a-range-was-a-range. Sorry about that confusion.

If I do the selection from top to bottom, it does indeed work as you
encountered:

$ vim -u NONE
:r !jot 15
3GVG:g/5/d
gv

But if I select them from bottom-to-top

$ vim -u NONE
:r !jot 15
V3G:g/5/d
gv

I get the (mis)behavior I was seeing...the "gv" doesn't reselect the
available range.

Again, sorry I messed up reproducing that situation.

-tim



Bram Moolenaar

unread,
Jul 19, 2020, 4:10:25 PM7/19/20
to vim...@googlegroups.com, Tim Chase, v...@vim.org
Hmm, now I can reproduce it. The mark on the last line has become
invalid. ":marks" shows the "<" mark as "invalid". Weird thing is that
when using "'<" it works, but it actually jumps to the ">" mark
position. The code shows that this is intentional.

I suppose that when the Visual mark is beyond the end of the file, it's
best to put it on the last line.

--
Light travels faster than sound. This is why some people
appear bright until you hear them speak
Reply all
Reply to author
Forward
0 new messages