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 ␊
.
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)!
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.
dge
doesn't "clear the buffer" at all because the motion doesn't include c
. Did you mean "The cursor is at c
"?d2ge
does nothing because, in your example, it is impossible to move the cursor to the end of the non-existing second previous word. Since there is an error in the motion, the operation is not performed.This is basically the same problem: both b
and ge
are impossible so the operation is not performed:
b
moves the cursor to the first letter of the previous word. No previous word → error → no motion → no operation.ge
moves the cursor to the last character of the previous word. No previous word → error → no motion → no operation.In other words, the behavior you describe is the expected behavior.