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 ![]()
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)
else
vim.cmd('normal! ' .. count .. key)
end
end
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
![]()