Seems like it's working logically to me.
The docs (:h text-objects
) give us three "rules":
- "a" commands: select "a"n object including white space
- "i" commands: select an "inner" object without white space OR just the white space
- the "inner" commands always select less text than the "a" commands.
There's also an unwritten rule that the selection should include already selected text (in our case the single character selected after hitting v
). I think the behavior most users expect is selection expansion not selection replacement where some selected text is deselected. Certainly we don't want to do expansion in some cases and replacement in others.
Finally, one has to accept that iwiw
is not the same as 2iw
. The former is two atomic operations, the latter one. That is, as soon as we hit the first w
in iwiw
Vim acts before continuing to process our input. So we can't expect the two input sequences to always behave exactly the same way even if, in practice, they do for most circumstances.
Let's look at examples. When in visual mode, on a line with "The quick brown fox jumped..." then, (replacing spaces with "." just for readability"):
With the cursor somewhere inside quick
aw
selects quick.
iw
selects quick
2aw
selects quick.brown.
2iw
selects quick.
With the cursor on the space between quick
and brown
aw
selects .brown
iw
selects .
2aw
selects .brown.fox
2iw
selects .brown
To follow the rules above there's really no other behavior possible for iw
in the second scenario than remaining with a single space selected.
If instead selected text was:
.brown
=> violates "object without white space OR just the white space" rule as well as "selects less than aw
"
brown
=> violates unwritten rule of not deselecting currently selected text (selection replacement)
Those are the only two alternatives that are remotely viable...and they don't follow the rules.
All of this is a (long winded) way of saying this is just a matter of having some simple rules with less-than-ideal behavior for one edge case.
v2iw
grows over single space as expected. Alsoviw2iw
works asviwiw
should. So indeed it looks like a bug. – Matt Nov 2 '19 at 17:42