How to Save & Exit in Vim Editor

By Amber D. Walker

The Vim (Vi Improved) text editor may have originally been written decades ago, but its powerful set of keystrokes and philosophy of "modal editing" still make it a favorite among Linux users and programmers. Nonetheless, it lacks many of the conventional user interface features of more recent editors, such as a main menu, so users are forced to learn keystrokes for all tasks.

Step 1

Press "Escape." This will take you out of "Insert" mode and into "Command" (or "Normal") mode.

Step 2

Type ":wq." The colon indicates that what follows is a Vim command, the "w" indicates that the file should be written, or saved, and the "q" indicates that Vim should quit, or exit.

Step 3

Add the filename at the end of the command if you are saving a new document. So, instead of ":wq", you should type ":wq filename.txt."

Tips & Warnings

  • If Vim objects to saving the file for any reason (such as if the file is marked as "read-only"), you can override this by adding an exclamation mark after the "q" in the command. This tells Vim to force the command and exit without saving.

References & Resources