Categories: Ubuntu

How to Save and Quit File in Vi/Vim Editor Command

If you new to Vi/Vim and you don’t know how to save and quit the file using Vi/Vim editor? Most of the users faced this common issue, Once they opened the file using Vi/Vim they don’t know how to save and quit the file in the Linux or Unix like operating systems. Here below you have the solution for that.

The following command will help you to open the file using vi or vim on the Linux/Unix server.

vim filename

Or

vi filename

How to Save and Quit File in Vi/Vim Editor Command

Once you are in the file and you don’t know how to save and quit the vi or vim editor here the below command will help you to do that.

Step-1

You like to insert your data by pressing insert key in Windows and for Mac Shift “I” to insert your data.

Step-2

Once you inserted your data and if you are currently in insert or append mode, press Esc key.

Step-3

Now you need to press : (colon) on your keyboard, Once you have done that the cursor should reappear in the editor.

Step-4

The main thing here you need to enter the following command (type :wq! and press Enter key) this will help to save and close the file. Below you have example screenshot.

Using :x! or :wq both will help to save and quit the vi/vim editor including all changes you have done to the document will be saved to the file.

How to delete all the changes in vi/vim

In the editor, you did all the changes but you don’t like to save the changes and now you like to quit the editor use :q! and press Enter to exit without saving the changes.

vim/vi commands

The following commands help to save and quit the file.

Command Description
Type :wq or :wq! Save and exit editor with your data.
Type :x! Save and exit editor with your data.
Type :q! or :q Close or exit your vi/vim without saving any changes in your editor.

The post How to Save and Quit File in Vi/Vim Editor Command appeared first on Linux, Angular, Angular JS, jQuery, PHP, MySQL and Web Development Tutorials.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

11 hours ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

1 day ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

1 day ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

2 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

3 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

4 days ago