kakoune: w and do not work as expected when end of selection falls on end of word.

Steps

Put the following text in a buffer:

c ccc ccc ccc
cc ccc ccc ccc

Move to the second line and do <a-h> to get your grey cursor to the beginning. If you do one <a-w>, the text "cc " at the beginning of the line will be selected. That’s what is supposed to happen. Now, try the same thing on the first line.

Outcome

The first “c” is not included in the resulting selection.

Expected

The first “c” should be in the selection.

Edit: A more refined test case:

    [   abcd]e     abc a                  w
       abc[de     ]abc a

OK, fine…

    [   abcde]     abc a                  w
       abcde[     ]abc a

…wait, what?

    [   abcde ]    abc a                  w
       abcde[     ]abc a

OK, I declare shenanigans.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

OK, good, I’m glad I’m not going insane, here.

w and <a-w> badly need to get unfucked. I also tried doing it the kakoune way, and found the same inconsistencies and more.

Why are these:

       ab[c]d    a abc ab        w
       ab[cd    ]a abc ab        
       abcd[ ]   a abc ab        w
       abcd[    ]a abc ab        

different from this:

       abc[d]    a abc ab        w
       abcd[    ]a abc ab        

Please tell me you can see this glaring irregularity in how the rules are enforced.

(I’m just now gave my first try to kakoune.)

Documentation as suggested:

w: select the word and following whitespaces on the right of selection end l: select the character on the right of selection end

(It means [selected text].)

How <kbd>l</kbd> works? [a]bc -> a[b]c. So selection doesn’t include the current character.

How <kbd>w</kbd> works? [a]bc -> [abc]. Identical word usage in documentation but selection includes the current character.

One more thing:

ab a abc abc
^  ^ ^   ^   where words beginning
  ^ ^   ^    whitespaces
^^ ^ ^^^ ^^^ word characters
             (there is nothing more here)

Now try it out in practice:

[a]b abc a abc        w
[ab ]abc a abc        d
[a]bc a abc           w
[abc ]a abc           d
[a] abc               w
a[ ]abc               d
a[a]bc                w
a[abc]                d
a[-]                  w
“no selections remaining”

It must be black magic because “a” is a word character that was simply skipped. I really want to know what’s the explanation of this, just please don’t tell it’s “documented” or “it works right”. Because it doesn’t… or if yes, I won’t thinking anymore whether I should switch to kakoune or not.


[…] If you have just “c” there is a word-start just there.

So you say <kbd>w</kbd> skips the current gray block, that’s why “c” didn’t become selected? Then it doesn’t work well in the 100-ε percent of cases.

[…] you see that the space between the words was selected, as documented.

Between? So you say too that space is surrounded by word characters? I can also confirm from several sources that “a” is classified as a word character.

If you want to select a word use <a-a>w or <a-i>w.

No. Sometimes people just simply need to “select the word and following whitespaces on the right of selection end” and they want to do it using <kbd>w</kbd> as documented.

Running commands dw should have the same result as cw<esc> but it doesn’t.

The explanation why. (You can switch it off in nvim.)

Similarly, vwd should behave like dw but it also doesn’t.

In Vim there are inclusive and exclusive motions and motions with v become inclusive.

I’ll try to deepen my reflection on the subject soon.

Meanwhile, after a bit of research, it turns out that the question was asked a while ago: https://github.com/mawww/kakoune/issues/752 but mawww explanation was pretty light.