Useful ex command is :so (short for :source)

This reads the contents of a file as a series of
commands. When you start vi it normally,
implicitly, performs a :source on ~/.exinitrc
file (and Vim usually does this on ~/.vimrc,
naturally enough). The use of this is that you
can change your editor profile on the fly by
simply sourcing in a new set of macros,
abbreviations, and editor settings. If you’re
sneaky you can even use this as a trick for
storing sequences of ex editing commands to apply
to files on demand.

For example I have a seven line file (36
characters) which runs a file through wc, and
inserts a C-style comment at the top of the file
containing that word count data. I can apply that
”macro” to a file by using a command like:
vim +‘so mymacro.ex’ ./mytarget

(The + command line option to vi and Vim is
normally used to start the editing session at a
given line number. However it’s a little known
fact that one can follow the + by any valid ex
command/expression, such as a “source” command as
I’ve done here; for a simple example I have
scripts which invoke: vi +‘/foo/d|wq!’
~/.ssh/known_hosts to remove an entry from my SSH
known hosts file non-interactively while I’m
re-imaging a set of servers).