How to Save a File in Vim

Saving in Vim is a Command-mode action: press colon, type a write command, and hit Enter. These commands cover saving, saving-and-quitting, and saving under a new name.

Steps

  1. Enter Command mode. From Normal mode press : to start a command (press Esc first if you are still typing text).
  2. Write the file. Type w and press Enter to save the current file.
  3. Write and quit. Type wq and press Enter to save and exit.
  4. Save under a new name. Type w newname.txt and press Enter to write a copy to a different file.

In the Vim Browser Editor

In the Vim Browser Editor, :w saves through your browser: it downloads the file, writes back to a file you opened, or stores it in your cloud workspace when you are signed in. :wq behaves the same as :w here because there is nothing to close. Instead of :w filename, the editor prompts you for a filename the first time you save a new buffer.

Try it in the editor

Related how-tos

Advertisement