Writing and quitting are separate Vim operations. Before entering an Ex command, press Esc to return to Normal mode, type :, enter the command, and press Enter. Read Vim's status or error message before assuming a write succeeded.
Advanced Text-Fu · Lesson 8
Vim Saving and Exiting
Learn how to write, quit, save under another name, or deliberately discard Vim buffer changes.