To save a file, you must first be in #Command mode. Press Esc to enter #Command mode, and then type :wq to write and quit the file.
- i Switch to Insert mode.
- Esc Switch to Command mode.
- :w Save and continue editing.
- :wq or ZZ Save and quit/exit vi.
More Info: https://linuxapt.com/blog/2-how-do-i-save-a-file-in-linux-command-line