4

I don't actually want f itself to wrap across lines, but I would like to know how I can create a single key mapping which will jump to the next instance of the letter which follows it.

The mapping could be f or something else; perhaps I would use <C-/> which seems unbound.

The intention is that it would operate sort of like a function, and would take the next letter as its argument and perform:

/<argument><CR>

Is this possible, or would there have to be a separate key mapping for every letter, e.g.

nnoremap <C-/>a /a<CR>
nnoremap <C-/>b /b<CR>
...

?

2

You could do something like this:

nnoremap <expr> <c-f> '/' . nr2char(getchar()) . '<cr>'

See :h getchar and :h nr2char for more info.

  • I can't seem to get this to work. I tried typing it in as an ex command (i.e. prefixing it with : starting from normal mode) but when I then tried <c-/> nothing happened. – Wildcard Mar 19 '16 at 8:39
  • Strange. Could you try to use f instead of <c-/>? – Karl Yngve Lervåg Mar 19 '16 at 12:35
  • Just tried it; still doesn't do anything. – Wildcard Mar 19 '16 at 12:40
  • Ok, that's very strange. This works as expected at my end. Did you remember the <expr> part? – Karl Yngve Lervåg Mar 19 '16 at 13:26
  • 1
    Same thing for me: it works with F2 but not <c-/>. – statox Mar 19 '16 at 15:43

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.