Inconsistent overkill behavior on various motions

13 views
Skip to first unread message

Brennan Vincent

unread,
Oct 18, 2020, 1:12:22 AM10/18/20
to vim...@googlegroups.com
I am investigating the behavior of various motions when [count] exceeds
the actual number of objects.

Given buffer "abc abc":

"2$" (with cursor on first column) does nothing (presumably an error).
"2^" (cursor on last column) has the same behavior as "^".
"2w" (cursor on first column) jumps to the last character on the line
(same behavior as "2e").

Comparison with the other vi implementations I have available:

Neovim matches the behavior of Vim.

Nvi errors on "2^"; otherwise the behavior is the same as Vim.

Zsh with `bindkey -v` matches Vim.

Readline apps in vi mode (e.g., bash with `set -o vi`) go as far as
possible in all three cases (i.e., they match Vim, except that on "2$"
they jump to the end of the line).


Brennan Vincent

unread,
Oct 18, 2020, 1:23:27 AM10/18/20
to vim...@googlegroups.com
Actually it seems nvi matches vim in all cases. So bash/readline is the
only outlier.

Tim Chase

unread,
Oct 18, 2020, 8:42:38 AM10/18/20
to Brennan Vincent, vim...@googlegroups.com
On 2020-10-18 01:12, Brennan Vincent wrote:
> "2$" (with cursor on first column) does nothing (presumably an
> error).

For the record, "$" does take a count, going to the end of the line
count-1 lines down. With only the single line, there's no count+1
line to go to, so both (n)vi and vim rightfully errors at you.

:help $

With more than one line you can observe the expected behavior. I'd
use "$" with a count more often if it did "count" lines rather than
"count-1" lines, because "count-1" requires doing the math in my
head. Just a little friction.

> "2^" (cursor on last column) has the same behavior as "^".
> Nvi errors on "2^"; otherwise the behavior is the same as Vim.

"^" doesn't take a count, so both (n)vi (at least here on FreeBSD &
OpenBSD) and vim ignore attempts to provide a count. I could see it
going either way here -- either erroring or just ignoring it.

> "2w" (cursor on first column) jumps to the last character on the
> line (same behavior as "2e").

There are some small "e" implementation differences between vi and
vim as detailed in `:help WORD` (right above `:help object-motions`)
but I don't think you're hitting this known case. I was surprised to
see that this nuance you encountered wasn't documented (as best I can
tell).

-tim






Brennan Vincent

unread,
Oct 18, 2020, 10:15:16 AM10/18/20
to vim...@googlegroups.com
On 10/18/20 8:42 AM, Tim Chase wrote:
> For the record, "$" does take a count, going to the end of the line
> count-1 lines down. With only the single line, there's no count+1
> line to go to, so both (n)vi and vim rightfully errors at you.

I get it. My point was that this logic applies for some motions, but not
others. In particular `w`, `j` and many others will go as far as they
can, not error if the count is too high.

Reply all
Reply to author
Forward
0 new messages