Vim has a handy feature that allows you to run commands from a file when you open a new session.
For example, suppose you have a file,
ggIHello World. To execute this, open MacVim with
/tmp/my-vim-commands. When the session starts, it will run those commands.
Then move to the top of the buffer, switch to Insert mode at the beginning of
the line, and enter the text “Hello World”.
To read commands in from stdin instead of an actual file, you can use
cat <<CMD | mvim -s /dev/stdin
Note: This doesn’t seem to work with console Vim, it throws an error “Vim: Warning: Input is not from a terminal”.