Vi is a command-line text editor for the Unix/Linux based systems. Vim (Vi IMproved) is feature rich successor of the Vi text editor with multiple enhancement and user friendly.

How to Save A File In Vi/Vim & Exit Editor Linux Tutorials vi vim

Let’s go through the first step to learn Vim to save and close file. This tutorial will help you to understand, how to save file on Vi/Vim and exit from editor.

How to Save Changes in Vim

In this part, you will learn, how to save changes in Vim without quiting the editor.

  1. Press ESC to switch to command mode.
  2. Type : (colon) to start command prompt at bottom-left of the editor.
  3. Type w just after the colon symbol and press Enter.

The above process will save changes in in current vi/vim editor. Your file will remain open in editor for further changes.

How to Save File and Quit in Vim

In this part, you will learn, how to save changes in Vim without quitting the editor.

  1. Press ESC to switch to command mode.
  2. Type : (colon) to start command prompt at bottom-left of the editor.
  3. Type w just after the colon symbol and press Enter.

The above process will save changes in in current vi/vim editor. Your file will remain open in editor for further changes.

Other Save and Quit Commands in Vi/Vim

In the above methods, you learned about save file and quit from vim editor. There are some other methods to handle other scenarios.

The first two steps will remain same as above:

  1. Press ESC to switch to command mode.
  2. Type : (colon) to start command prompt at bottom-left of the editor.

Now, use one of the below commands as per your requirements.

Command Meaning
:w Write changes to file without closing editor.
:wq Write changes to the file and close editor
:wq! Forcefully write changes to file and quit even if file has only read permission
:q Quit the editor (Only if not changes has been made to file)
:q! Quit the editor with dicarding any changes made in file.
:w new-name Save file contnet with a new file name.
:x Close file with save changes.

Conclusion

If this tutorial helps you to understand about how to save and quit from file in vi/vim editor. If this helps or need any changes in this tutorial, please comment.