Rin
Rin

Reputation: 11

Key binding in VIM

How can I bind key and its options?

Example: dw - deletes one word. d3w - deletes three words. I want to use eo to delete one word, and e3o to delete three words. I can bind d to e, but the problem is I cannot bind option/movement key (e.g w to o in this example).

I tried:

nnoremap e d|xnoremap e d
nnoremap eo dw|xnoremap eo dw

or

nnoremap o w|xnoremap o w
nnoremap e d|xnoremap e d

Upvotes: 0

Views: 560

Answers (1)

Ultcyber
Ultcyber

Reputation: 406

What you're looking for is "operator pending mappings". You can remap the movement keys to specific actions.

In your case what you need to do is remap d to e

:nnoremap e d

And then remap the "w" movement to "o"

:onoremap o w

With this, both eo and e3o work.

Check this guide for a detailed description https://learnvimscriptthehardway.stevelosh.com/chapters/15.html

BTW: not sure if it's the best practice to remap VIM keybindings for basic actions such as deleting/inserting etc. as it can possibly mess up other bindings - unless some very specific usecase, maybe consider learning the default ones.

Upvotes: 4

Related Questions