How can I make a vim function wait for a single key press?
Example:
- create a function NextOccur that is mapped to execute when key
fis pressed - when
fis pressed nothing should help right away - after the next key (let’s say
x) is pressed, the cursor should move to the next ocurrence ofx
PS: Yes, I know that’s exactly what
fdoes by default (although its only linewise), but I was wondering if WE could implement functionality like this, ourselves
What if I want to wait for the next two keypresses, is that also possible?
You can use the built-in
getchar()function. It waits for a single keypress and then returns it. For an ordinary 8-bit character, you have to usenr2char(getchar())to convert it to a String.It seems you want to extend the
f/tcommands to cover multiple lines, too. Be aware that there are already plugins that do that, for example ft_improved.