BUG: 2dd does not delete on last line

67 views
Skip to first unread message

Ingo Karkat

unread,
Jul 16, 2013, 10:17:10 AM7/16/13
to vim...@googlegroups.com
Hello Vim developers,

This was first reported on Stack Overflow:
http://stackoverflow.com/questions/16710886/why-does-3dd-not-work-from-the-last-line-in-vim

vim -N -u NONE -c "for i in range(1,3)|call setline(i,i)|endfor"
:normal! 3G3dd
" BUG: This just beeps, nothing gets deleted. Expected: Current last line gets deleted.
:normal! 2G3dd
" OK: This deletes lines 2 and 3, as expected, even though the count is larger than the number of lines.
:undo
:3delete 3
" OK: The equivalent Ex command correctly deletes the last line.

Reproducible on Vim 7.4a.24 on Linux/x64, and also on ancient Vim 7.0.000 on Windows/x86.

-- regards, ingo

glts

unread,
Jul 16, 2013, 10:21:23 AM7/16/13
to vim...@googlegroups.com

Ingo Karkat

unread,
Jul 16, 2013, 10:32:57 AM7/16/13
to vim...@googlegroups.com
To quote Bram:
This is intentionally implemented this way in cursor_down().
It doesn't say so, but it is most likely to be Vi compatible.

Then isn't this a case for 'cpoptions', as with all the other Vi
peculiarities?!

There are now at least 4 people (the submitter on SO, one who answered,
myself, and Nikolay from the linked thread) who consider this to be a
bug. If the group of people where this doesn't fit their mental model is
way larger than those who know about this (without diving into the
source code), and there are no convincing reasons for keeping the
peculiarity, and the probability of someone actually relying on the
behavior goes against zero, that's a strong case for fixing it (when in
:set nocompatible).

-- regards, ingo

Bram Moolenaar

unread,
Jul 16, 2013, 11:21:23 AM7/16/13
to Ingo Karkat, vim...@googlegroups.com
Maybe it's a bug that when you tell Vim to delete lines that don't exist
it doesn't beep and do nothing. But it's always been that way and there
is no reason why it's more of a problem now then 10 years ago. So let's
just leave it.

--
Lower life forms have more fun!

/// 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 ///

Ingo Karkat

unread,
Jul 16, 2013, 12:21:07 PM7/16/13
to vim...@googlegroups.com, Bram Moolenaar
The worst in my eyes is the inconsistency: Only in the last line does
Vim reject a count that doesn't fit, whereas in previous ones it
silently truncates to what's available.

> But it's always been that way and there is no reason why it's more of
> a problem now then 10 years ago.

That's because it's an obscure corner case. I probably would have never
noticed, just repeated my command without the count, and never reflected
what happened. But some people do notice (even take the time to inquire
about this), and also for me, it subconsciously throws me "out of
rhythm" when this happens.

> So let's just leave it.

Well, all I'm asking is to put it on the endless TODO list, where it
will probably stay for a long time until someone volunteers a patch :-(

Sure, this could be "just documented", but wouldn't a fix (that almost
noone will notice) be cleaner and more satisfying, because it's The
Right Thing?!

-- regards, ingo

Adri Verhoef

unread,
Jul 16, 2013, 12:30:50 PM7/16/13
to vim...@googlegroups.com
Ik ben het met je eens, Bram, je schreef op 2013-07-16 17:21:

> Maybe it's a bug that when you tell Vim to delete lines that don't
> exist
> it doesn't beep and do nothing. But it's always been that way and
> there
> is no reason why it's more of a problem now then 10 years ago. So
> let's
> just leave it.

Je kunt inderdaad geen regels weggooien die er niet zijn en zo is het
altijd geweest.

Groetjes,
Adri

Tony Mechelynck

unread,
Jul 16, 2013, 6:23:26 PM7/16/13
to vim...@googlegroups.com
Or for those who don't understand Dutch: "You can ideed not throw away
any rules that aren't there, and it has always been that way."

>
> Groetjes,
> Adri
>
Best regards,
Tony.
--
I have the power to HALT PRODUCTION on all TEENAGE SEX COMEDIES!!

Bram Moolenaar

unread,
Jul 17, 2013, 7:43:57 AM7/17/13
to Tony Mechelynck, vim...@googlegroups.com

> On 07/16/13 18:30, Adri Verhoef wrote:
> > Ik ben het met je eens, Bram, je schreef op 2013-07-16 17:21:
> >
> >> Maybe it's a bug that when you tell Vim to delete lines that don't exist
> >> it doesn't beep and do nothing. But it's always been that way and there
> >> is no reason why it's more of a problem now then 10 years ago. So let's
> >> just leave it.
> >
> > Je kunt inderdaad geen regels weggooien die er niet zijn en zo is het
> > altijd geweest.
>
> Or for those who don't understand Dutch: "You can ideed not throw away
> any rules that aren't there, and it has always been that way."

s/rules/lines/:-)

--
The only way the average employee can speak to an executive is by taking a
second job as a golf caddie.
(Scott Adams - The Dilbert principle)
Reply all
Reply to author
Forward
0 new messages