vimneovim

Strange behaviors of vim omap ge


I found two strange behavior with omap in vim 8.2, vim 9 and nvim 0.10.2. It may apply to all operators (at least d, y, c, which I've tested), but I will pick d as an example below.

Denote end-of-line with .

Case 1

The buffer is

␊
abc␊

The cursor is at b.

With dge, the buffer is cleared except for c, no surprise. However, with d2ge (or 2dge which is equivalent, or d3ge, d4ge, etc.), the cursor moves to the beginning of the first line, and nothing is deleted (or for operator c, we are not left in insert mode)!

Case 2

The buffer is

abc␊

The cursor is at a. With db, nothing changes. This is because b is exclusive. However, with dge, which is inclusive, again nothing changes!

I tried to find in manual, yet with no luck. Can anyone explain such behavior, hopefully with reference to vim's manual? Thank you so much!

Why this is useful to me: I'm developing a vim plugin that extends vim word motions to languages without word boundaries like Chinese. One important feature is to be compatible with vim on ASCII text. Therefore, I need to understand such behavioral details in vim/nvim.


Solution

  • Case 1

    Case 2

    This is basically the same problem: both b and ge are impossible so the operation is not performed:

    In other words, the behavior you describe is the expected behavior.