3

I would like to have the keys M, J, K, L, U, I, O to be mapped to 0, 1, 2, 3, 4, 5, 6 (combine with the keys 7, 8, 9 already being on top of those keys) to be a total numpad when I hold a modifier key, say Alt/Meta.

In that way commands with numbers like 25j, d3w, etc. would be easier and faster to be typed. But I haven't figured out how to make this happen.

As it is said in this answer https://vi.stackexchange.com/a/2363/21584, I've tried this solution:

execute "set <M-j>=\ej"
nnoremap <M-j> 1

But it only works with commands which begin with a single number (7j), however complex commands which have number inside or multiple number (d3w, 25j) don't work.

I use Ubuntu 18.04, on terminal Kitty.

4
  • @klaus my bad, I mean Ubuntu 18.04. But I think that doesn't really matter.
    – Bui Trung
    Mar 31, 2019 at 5:03
  • copy-paste all the codes in your vimrc regarding this mapping, i.e. not just <M-j> but all of <M-k> etc. It would be easier for people to copy-paste themselves and as a result more easier to help you.
    – 3N4N
    Mar 31, 2019 at 5:26
  • Creating mappings for this is potentially very hard—youd have to accept keypresses as long as it’s a « number » and then, when it’s not, feedkeys it all back to vim.
    – D. Ben Knoble
    Mar 31, 2019 at 13:24
  • @klaus, Knoble thanks I've got the solution, please check out my answer it probably could help you too.
    – Bui Trung
    Mar 31, 2019 at 14:52

1 Answer 1

3

As I find out in this guide: https://howchoo.com/g/nzc1ztu4ztd/custom-key-mappings-vim#triggering-our-custom-key-mapping

What I was missing was the Operator-pending Mode, which is the case of the command like d3w.

This is how I modified the mappings (I didn't think it would turn out to be this simple):

noremap ^[j 1
noremap ^[k 2
noremap ^[l 3
" etc.

Where ^[ is the Escape character, and map applies the mapping for Normal, Visual and Operator-pending Mode. Now I can use Alt + J K L... to simulate the numpad on the right hand. Typing commands containing numbers is feeling more and more comfy now.

Hope this could help you guys :)

2
  • 1
    Consider using :h :noremap version of :h mapmode-nvo
    – 3N4N
    Mar 31, 2019 at 14:55
  • Thanks, it makes more sense to use noremap
    – Bui Trung
    Mar 31, 2019 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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