why only vi? from the way i see, you just need to do something to a file and save it. So you can also use sed/awk to do the job.
If you still want to try vi, here's one way, not the best, but still does something.
sun# echo "test" > file
sun# more file
test
sun# vim -c "%s/test/changed" -c ":wq" file
sun# more file
changed