2

I use d/ a lot, so I decided to map / as follows:

:nnoremap <leader>j / (where <leader> is my space bar)

To my surprise, d<leader>j doesn't work. Why is that? I expect it to behave like d/.

I should add that <leader>j alone triggers the /, so it is indeed correctly mapped!

0
5

When you hit d, an operator, you enter Operator-pending mode. Vim will then wait for a motion command to be entered. In other words, when you follow d with <leader>j that's not happening in Normal mode...the mode for which you've mapped those keys.

For Operator-pending mode you need to use the :omap family of mapping commands, so...

:onoremap <leader>j /

Fortunately, there's a mapping type, :map, that encompasses both Operator-pending and Normal mode so you can kill two birds with one stone using

:noremap <leader>j /

However, this also includes Visual and Select modes so you need to be mindful of that. If that causes problems then just create two mappings (:omap and :nmap types).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.