I'm trying to create something of a "new mode" in vim. The details of the mode are unimportant, but there is one thing I need to be able to do.
I need to do something like the following pseudo-code:
get user input (movement keys like "j" or complex keys like "dd")
while user_input != <esc>
execute the user input
endwhile
In other words, I need a loop that will read what the user is doing, then perform the associated action.
I've already got the following code:
let char = nr2char(getchar())
while char =~ '^\w$'
execute "normal ". char
let char = nr2char(getchar())
endwhile
This works fine for user movements (j
, k
, etc.), but fails for more complex multi-character commands like dd
.
Also, this is a small annoyance, but the cursor disappears during getchar(), meaning you effectively can't see the cursor (this is of less importance because of what I'm trying to do, but hopefully has a solution as well).
Does anyone have any idea how I can get multi-character actions to work?
I think you might be interested in submode.vim, if not to use it, to at least see how they've implemented this feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With