0

I want to make more use of fF to navigate, but find the f to be clumsy. Eg. jump to "a" is fa.

Instead, I'd like aaa to map to fa, bbbto map to fb etc.

Is there an easy way to do this other than lots of :nmap aaa fa? I'm all in on Neovim, so lua solutions are ok.

Alternative approaches also welcome.

2 Answers 2

1

You can do this with a loop:

for c in range(97, 122)
  for offset in [0, 32]
    let key = nr2char(c - offset)
    execute "nnoremap " .. repeat(key, 3) .. " f" .. key
  endfor
endfor

Personally, I would find this unusable, though, as now every normal-mode command you issue will have a delay while Vim waits for your 'timeout' to see whether you're typing your mapping.

On the up side, it would force you to use motions properly as you can no longer spam motions repeatedly to get places!

1
  • thx. That worked well. I didn't find the timeout to be an issue. Unfortunately, the issue I did find was that folke/which-key.nvim got confused by my intentions. I've reverted to "<space><space> f" & "<space><space><space> ;"
    – pinoyyid
    Commented Jul 27, 2022 at 12:09
2

Something like

for c in ['a', 'b' ......]
    exe "noremap " . repeat(c, 3) . " f".c
endfor

But honestly I wouldn't do that because you will hide all other legit keybindings.

  • aaa is append "aa"
  • bbb is back, back, back
  • ccc is change line with "c"
  • ddd is delete line, and prepare to delete something else
  • and so on.

Even if you think you won't need "append aa", the first "a" still says: "I'm changing the current mode with append", etc.

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.