Starting vi and Saving Files
vi filename
- start editing filename, create it if necessary
Saving the file you’re working on and/or leaving vi:
:wq
- write the file to disk and quit
:q!
- quit without saving any changes
:w! newfile
- write all lines from the entire current file into the file ‘newfile’, overwriting any existing newfile
:n,m w! newfile
- write the lines from n to m, inclusive, into the file newfile, overwriting any existing newfile