I can think of two ways to do this.
The first way assumes you own the file, but the file is READONLY.
Just use vi's exclamation mark suffix to the write command (:w!) to force overwriting your own READONLY file. This of course assumes that you have permission to write and execute in the current folder.
will cause vi to overwrite the original READONLY file.
The second way assumes someone else owns the file, and you would like to save your changes to that file.
One way to accomplish this is to save the changes made to the original file as an ed script from within vi. This ed script may be applied to the original file (or other similar files) at a later time outside of vi with the ed line editor.
A way to save the current edit session as an ed script is to pass the original file name and the edited vi buffer as standard input to the diff utility with the --ed command line switch i.e. display differences as an ed script.
So, assuming an edited vi buffer, then perform the following
:.,$!diff --ed [original_file] -
This replaces all lines in the current buffer (.,$!) with the diff generated ed script (diff --ed [original_file] -) necessary to convert the original file into the contents of the current buffer. We then want to save this ed script away to a safe place, and apply the script to a version of the original file we can write to. So, save the script away to a writable location, for instance, your login folder:
Now exit vi, and use this ed script to obtain the the edited file that couldn't be saved in the first place. Here is how to accomplish that from the bash command line prompt, '$':
$ (cat ~/my_ed_script && echo 'w') | ed - writable_copy_of_original_file
What this command sequence does in words is to catenate the script we generated with diff and echoes the ed write command, 'w', to the standard input of ed. Ed then applies this script to the writable copy of the original file, and writes those modified buffer changes back out to the file.
So that is a way to save work performed in vi to a file which had originally been owned by someone else using vi, diff, and ed.