I am trying to use the command line window in a vimscript.

Unfortunately, the experiment I have with is not good and I am not able to achieve the following:

normal! q:

This should open the command history buffer, but the normal doc states:

{commands} should be a complete command.  If
{commands} does not finish a command, the last one
will be aborted as if <Esc> or <C-C> was typed.

Do you know if there is a way around this limitation?

  • 1
    Maybe you could use feedkeys() to add the keys q: in the typeahead buffer: :call feedkeys('q:', 'in') Jun 16 '16 at 10:50

You could use the feedkeys() function to add the keys q: inside the typeahead buffer:

call feedkeys('q:', 'in')

feedkeys() waits for one argument (the keys you want to add), and a 2nd optional one which contains some flags.

In the previous command, 2 flags are used i and n.

i means that the keys won't be appended to the typeahead buffer but inserted (in other words they should be typed before the already present keys, not after). Maybe you won't need this flag, I don't know, but the few times where I needed feedkeys(), I needed i so I thought it would be a good idea to mention it.

n means that the keys won't be remapped. It's similar to the bang after :normal!.

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.