vi close and save file code example
Example 1: vi save and exit
//Save
:w
//Exit
:q
Example 2: vi quit and save
# ESC to start command prompt, then
:q! # exit vi without saving
:wq! # exit vi with saving (! means exiting even if file is read only)