How To Exit A File In Vi / Vim Editor In Linux - Tecmint
Có thể bạn quan tâm
In this article, we will learn how to exit Vi/Vim (after referred to as Vim) text editor using simple commands. In a previous article, we explained a simple tip on how to save a file in Vi or Vim after making changes to a file.
Before we move any further, if you are new to Vim, then we recommend reading through these 10 reasons why you should stick to using Vi/Vim text editor in Linux.
To open or create a new file using Vi/Vim, simply type the commands below, then press i to switch to insert mode (insert text):
$ vim file.txt OR $ vi file.txt
After making changes to a file, press [Esc] to shift to the command mode and press :w and hit [Enter] to save a file.

To exit Vi/Vim, use the :q command and hit [Enter].

To save a file and exit Vi/Vim simultaneously, use the :wq command and hit [Enter] or :x command.

If you make changes to a file but try to quite Vi/Vim using ESC and q key, you’ll receive an error as shown in the scrrenshot below.

To force this action, use ESC and :q!.

Additionally, you can use shortcut methods. Press the [Esc] key and type Shift + Z Z to save and exit or type Shift+ Z Q to exit without saving the changes made to the file.
Having learned the above commands, you can now proceed to learn advanced Vim commands from the links provided below:
- Learn Useful ‘Vi/Vim’ Editor Tips and Tricks to Enhance Your Skills
- 8 Interesting ‘Vi/Vim’ Editor Tips and Tricks for Every Linux Administrator
In this article, we learned how to exit Vim text editor using simple commands. Do you have any questions to ask or any thoughts to share? Please, use the feedback form below.
Từ khóa » Vi Commands Exit
-
More Linux Resources
-
How To Exit (Quit) Linux Vim/Vi Editor - PhoenixNAP
-
How To Exit (quit) Linux Vi Editor With Or Without Saving Changes Step ...
-
How To Exit The Vi Or Vim Editor - How-To Geek
-
Quit The Vi Editor Without Saving Your Changes
-
How To: Vi / Vim Save And Quit The Editor Command - NixCraft
-
How To Exit Vim – Vim Save And Quit Command Tutorial
-
How Do I Exit Vim? - Stack Overflow
-
Saving Changes And Quitting Vi
-
How To Exit From Vi In Linux Code Example
-
Basic Vi Commands - Colorado State University
-
How To Exit Vim? Multiple Ways To Quit Vim Editor - It's FOSS
-
How To Save A File In Vim / Vi And Quit The Editor - Linuxize
-
10 Ways To Quit/Exit From Vim Editor In Linux/UNIX? Examples - Java67