4

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') – user9433424 Jun 16 '16 at 10:50
4

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!.

| improve this answer | |

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.