Blog

03/06/2019

Vi / Vim Quit Without Saving Command



I am a new vi / vim text editor user. How can I quit the vi / vim text editor without saving my changes to a file under Linux / Unix like operating systems?

vi or vim is a text editor. You can use it to edit configuration files. Write programs in Perl, Python, C/C++, sh/bash/ksh and more. To exit or quite the vim/vi text editor without saving any changes press:
:q! ENTER
Let us see vi and vim commands in details.

How to quit the vi/vim editor without saving your changes

You can quit the vim or vi text editor without saving any changes you may have made to the file as follows:

  1. First, you need to press Esc key to get out of insert or append mode.
  2. Next type colon (: symbol)
  3. You see the cursor at the lower left corner of the screen.
  4. Finally, type the following command to quit without saving anything to a file:
    q!

Fig.01: Vim / vi text editor quit without saving changes command demo

This will force vi/vim to quit the editor, and all changes you have made to the document will be lost forever. You just discards any changes you made to the file.

Getting more info on how to use vim text editor

The vim or vi text editor has three modes. It has many commands and options for both new and advanced users. I strongly suggest that you start learning vim by typing the following command at the terminal:
$ vimtutor
Vimtutor starts the Vim tutor. Very useful for people working in IT, sysadmin jobs, and developers that want to learn their first Vim commands. Many commands works with vi too.

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....
12/08/2019

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...