When declaring a mapping with omap
or onoremap
i would like to be able to handle the case where the motion will be blockwise, linewise or standard.
For example let's consider the following block:
abcd
efgh
ijkl
mnop
Cursor is on the letter f. Suppose that I define an operator map from K
to :normal! vjl
(go to letter k).
onoremap K :normal! vjl<cr>
Interestingly enough when I run dvK
, dK
, d^VK
I get respectively
abcd abcd abcd
el el eh
mnop mnop il
mnop
But when I run dVK
it won't work, I get exactly the same as with dvK
.
I tried to use visualmode()
(mapping defined as @=visualmode()<cr>jl<cr>
but this does not work. It seems that the return value of this function is not immediately affected when you use v
, V
or CTRL-V in operator-pending mode.
Does anyone have a clue please?
Thank you
To achieve what you desired, you can simply define
onoremap K :<c-u>normal! jl<cr>
Note this motion, as formed by a ex-command, is always characterwise (see :h movement
Then you can freely use dv
, or dV
, or d^V
to force the motion to be another type and get what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With