Like everything else in
vi, there are several ways to save our edited files. We have already covered the ex command
:w, but there are some others we may also find helpful.
In command mode, typing
ZZ will save the current file and exit
vi. Likewise, the ex command
:wq will combine the
:q commands into one that will both save the file and exit.
:w command may also specify an optional filename. This acts like a Save As command. For example, if we were editing foo.txt and wanted to save an alternative version called foo1.txt, we would enter the following:
While this saves the file under a new name, it does not change the name of the file you are editing. As you continue to edit, you will still be editing foo.txt ...