Having trouble modifying "count" in my custom mapping (empty register)

Context: I’m experimenting with an idea where relative line numbers are represented in base 5 (digits 1-5). This allows you to type numbers using your left hand, and j/k with your right hand. It’s all about improving comfort and speed! If you think this is silly, well, I’m not sure what to say :stuck_out_tongue:

I’m using a sign column to render my custom line numbers. That part is easy.

But remapping j/k is proving to be trickier than I thought. I’ve spent roughly 8 hours at this point (hey, at least I’m learning).

I’ve gotten pretty damn close with the following lua:

local function alter_count(key)
  local count = normalized_count(vim.v.count1) -- Custom function that converts a base-5 number (14) to a real number (9).
  local mode = vim.api.nvim_get_mode().mode

  if mode == 'no' then
    vim.cmd('normal! ' .. vim.v.operator .. count .. key)
    vim.cmd('normal! ' .. count .. key)

vim.keymap.set({ 'n', 'v', 'o', 's' }, 'j', function() alter_count('j') end, { noremap = true })
vim.keymap.set({ 'n', 'v', 'o', 's' }, 'k', function() alter_count('k') end, { noremap = true })

This seems to work almost perfectly. There’s just one little problem. If I type y<count>j, nothing is yanked to the register! Oddly enough, the command tells me “X lines yanked to register”, but when I attempt to paste, I get a Nothing in register ". In fact, I don’t see the data in any register.

I’ve tried printing the command and manually running it in command mode. And it works! So I suspect that the mapping itself is mishandling the register.

Is there something I’m missing? Or am I running into the limits of the API?

Please help me solve this so I can go to sleep in peace :joy: :sob:

Using vim.api.nvim_feedkeys(vim.v.operator .. normalized_count .. key, 'n', true) when in operator mode seems to fix the issue. Still need to verify, but I feel like I’m unblocked.

Sorry for being unresponsive to your request, but…
Shouldn’t it be digits 0-4? Unrelated, but in your comment “real number” might be better as “decimal number”.

Not quite.

My goal is to reduce strain on the right hand as I jump up and down.

I want to be able to type the digits with my left hand (1-5), and j/k with my right hand.

“0” is typed with the right hand, at least on all the keyboards I’ve used.

I’ve spent the last week using my plugin, and it’s working really well. I think I’ve accomplished my goal.

I’ll post a link to the source code shortly. Again, it’s experimental.

I released the first version of my plugin. I found a much simpler way to accomplish my goals above.

Feel free to check it out: GitHub - mluders/comfy-line-numbers.nvim: A Neovim plugin that makes vertical motions more comfortable