Well, if it is a professor-problem, then play with the ex/vi options on those man pages and other online references to see what you can do. Either ex or vi can be drive by canned scripts into stdin. I have done it, using tools like "diff3 -e" to generate the file with all the changes of two different mods of an original (I think of it as the 4th corner of a square, given zero changes, zero + x changes and zero + y changes, create the file with zero + x + y changes. It helps if you use lots of lines when writing code, not being a one line showoff. Parallel development on a budget.)
Take a tip from diff3/diff -e: the line numbered modifications are created in
descending line order, so the line numbers "ahead" are not changed by the mods already applied. You can pull, modify or add the diff/diff3 -e generated mods, as long as you preserve descending line order.
When using :commands, you are essentially in ex not vi. This is more likely useful when scripting, and a good start toward learning sed and ksh command line editing.
Beware that for big files, g and v line deletions can be a quadratic or n-squared sort of problem, as g/xxx/d deletes mean the entire file is reworked with for each hit. Sometimes it is better to grep out the lines you want into a new file, or just move them within the file, like to $ = the end ( g/xxx/m$ ). ex/vi seems to do this without reorganization!