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.
Add a comment
|
1 Answer
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.– fbenceJan 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 ♦Jan 18, 2022 at 1:45