I know I can start vim with a command by executing vim +"MyCommand", but if MyCommand takes a parameter it would be nice to start vim, as if I already typed :MyCommand but not actually executing it, so I can pass the argument with vim open, rather than from the command line (use case would be a trivial alias in bash). I tried vim +"normal :MyCommand" but that doesn't work it seems.

1 Answer 1


You can use feedkeys():

vim +'call feedkeys(":MyCommand")'
  • @Quasímodo How is that possible? It feels like you would need to have : somehow overridden in the vimrc for this NOT to work? Also as a ps.: making an alias with this is not trivial because of the amount of quotes, so ended up making a function.
    – fbence
    Commented Jan 17, 2022 at 17:52
  • There is an argument to feedkeys to prevent mappings from expanding. Re: the shell, yes, a function of script should be much easier to work with.
    – D. Ben Knoble
    Commented Jan 18, 2022 at 1:45

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.