Linux logo

Ways to Exit Linux/Unix Vim

What is Vim?

Vim is a text editor that is upwards compatible to Vi. It can be utilized to edit all types of plain text. It is specifically beneficial for modifying programs.

There is a great deal of enhancements above Vi: multi-level reverse, multi-windows and buffers, syntax highlighting, command line modifying, filename completion, on-line assistance, visual choice, and so on.

Vim is a Unix text editor that’s included in Linux, BSD, and macOS. It’s known for being quick and effective, in part since it’s a small application that can run in a terminal (although it also has a graphical user interface), however mainly due to the fact that it can be controlled totally with the keyboard without any requirement for menus or a mouse.

For example, to place text into a file, you push I and type. To navigate or to run a command (such as Save, Backspace, Home, End, and so on), you press Esc on your keyboard and then press whatever essential or essential combination refers to the action you wish to take. It’s a very different way of modifying text compared to what contemporary computer system users anticipate, however, it’s the way Unix admins all over the world edit config files, changelogs, scripts, and more.

So, How to Exit Vim?

Enough of Vim intro, that you might already know, lets come to the topic of this tutorial; how to exit vim with or without saving.

Exiting Vim without saving

Follow these steps to exit the vim without saving the changes:

Step 1:

Press : <Esc>

(You should remain in insert or append mode if not, just begin typing on a blank line to get in that mode).

Step 2:

Press: <colon>

The cursor must come back at the lower left corner of the screen next to a colon prompt. The colon shows that what follows is a Vim command.

Step 3:

Type this:

q!

and press Enter.

This will close the editor, and abandon all modifications you have made; all modifications to the file will be lost.

Save then Exit the Vim

In order to first save the file and then exit, follow these steps:

Step 1:

Press <Escape>

(You need to be in insert or append mode if not, just start typing on a blank line to enter that mode).

Step 2:

Press : <colon>

The cursor ought to reappear at the lower-left corner of the screen beside a colon prompt. The colon shows that what follows is a Vim command.

Step 3:

Type the following:

wq

The “w” indicates that the file must be written, or saved which will overwrite the existing file and the “q” shows that vim must quit, or exit.

Finally, press the Enter.

This will quit the editor, and write all modifications you have actually made; all changes to the document will be conserved.

How to exit Vim using shortcut keys?

You may also close the Vim editor by using shortcut keys.

Press Esc >Shift + ZZ

This will save the file contents and then exit.

For quitting without saving the contents:

Press Esc > Shift + ZX

Summarizing the options (above + more) for quitting Vim

Here’s a list of commands for existing Vim:

Escswitch to command mode.
: wwrite out modifications that were made.
: qexit Vim.
: q!Exit without saving the changes made in file.
: wqSave the changes, and exits Vim.
: xSave the file contents, and closes the Vim.
How to see changes made in file?

After exiting you can display the contents of the file by using this command.

$ cat filename