You’ll want to save changes to your documents frequently, especially as you’re learning to use vi (Figure 4.12). Until you’re accustomed to switching between command and input mode, you may accidentally type in commands when you think you’re typing text, with unpredictable results. To save files, just follow these steps.
✓ Tips
If you’ve already saved your file at least once, you can save changes and exit vi in one fell swoop. In command mode, type :wq (for “write quit”). For more information about quitting vi, see the section called Exiting vi later in this chapter.
If you want to save a file over an existing file (obliterating the original as you do), use :w! existingfilename in command mode. The ! forces vi to overwrite the original.