save and close in vim 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)