How to Save and Quit vi/vim Text Editor

This post will guide you how to launch vim or vi Text editor to open a new file under Linux operating system. How do I save a file and quit from the current vi or vim text editor in Linux.

What is vi or Vim Test Editor


save and exit vi vim text editor5Vim or vi is a text editor for Unix or Linux system, and it is also designed for both from a command line interface and as a standalone application in a graphical user interface. And vi or Vim is a free and open-source software. You can use this text editor to create new files or edit configuration file under Linux system.

Vim is a highly configurable text editor for efficiently creating and changing any kind of text. It is included as “vi” with most UNIX systems and with Apple OS X.

Launch vi/vim Text Editor


For a vi or vim text editor user, if you want to create a new file under Linux terminal, and you can use vi or vim command with your file name, just type the following command:

$ sudo vi filename
$ sudo vim filename

save and exit vi vim text editor1

Exit without Saving Changes


If you have created a new file with vi or vim text editor, and you want to exit vi or vim text editor without saving any changes, you need to do the following steps in your current vim or vi text editor:

Step1: press the Esc key to quit the insert mode to command mode.

Step2: type :q! in command mode

save and exit vi vim text editor2

Step3: press Enter key on your keyboard. Then it will quit your current text editor and discard any changes you made before.

Exit with Saving Changes


If you want to save and quit the current vi or vim text editor with saving any changes under Linux terminal, you can do the following steps:

Step1: if you are in the Insert mode, then you need to press Esc key on your keyboard to back to command mode.

save and exit vi vim text editor3

Step2:  press colon character (:) in the command mode, and then enter the x! or wq, then press Enter key to quit the current text editor, and all changes in your file should be saved.

save and exit vi vim text editor4

Conclusion


You should know that how to create or save files with vi or vim text editor and exit the text editor under Linux operating system. If you want to see more detailed information about vi or vim text editor , you can directly go to its official web site.

You might also like:

Sidebar



back to top