Here's a couple more techniques you can use.
You can pass ex commands into Vim by using the
-c command line option or its shortened version,
vim foo.txt +'normal! xp' +':wq! bar.txt'
(Note that the
:wq! command can take a filename argument: it's slightly more concise to use this rather than
Using a script with
Similar to the
-S option described by @D. Ben Knoble, you can use the
-s option to run a script interpreting its contents as keystrokes.
Create a file named e.g.
my_script with the following contents, being sure to press Return at the end of the line so that the file contains two lines in total (the second being a blank line):
Then run this script:
vim foo.txt -s my_script
See also the
-w option, which you can use to record a script that can be executed with the