0

This is what it says in the help:

'x' Execute commands until typeahead is empty.  This is
    similar to using ":normal!".  You can call feedkeys()
    several times without 'x' and then one time with 'x'
    (possibly with an empty {string}) to execute all the
    typeahead.  Note that when Vim ends in Insert mode it
    will behave as if <Esc> is typed, to avoid getting
    stuck, waiting for a character to be typed before the
    script continues.
    Note that if you manage to call feedkeys() while
    executing commands, thus calling it recursively, then
    all typeahead will be consumed by the last call.

But I'm not sure what it means. I'm assuming it means that the function will execute the command string, and then it waits for the typeahead buffer to be empty before returning, but I'm not so sure.

Can anyone explain what it actually does, if possible with some examples?

2 Answers 2

0

Actually, help says it all. If "x" is not specified then keys are simply put into an internal buffer to process them later during main loop. But if "x" is there then the buffer will be executed before returning to caller.

This is done by invoking some other internal function, the one that also implements the "normal" command. And so it gets very "similar to using normal!", obviously. In particular, at the end you cannot stay in mode other than Normal.

Yet the difference between "feedkeys-x" and "normal" is that "normal" executes only "untyped" part (typically, the one that has been just inserted into the buffer's head) and stops. While "feedkeys-x" executes the whole buffer.

0

My understanding is that with the x option the feedkeys function will execute the part of the part of the script understood by Vim and empty the typeahead part that is not complete (Actually the exact opposite of what you guessed)

e.g.:

:call feedkeys('di')

Do nothing but filling the typeahead (lower left corner) with di. If you type w Vim will delete the current word.

:call feedkeys('di', 'x')

Do nothing since di is not a complete command and the typeahead is empty after the call.

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.