How To Exit Vim Text Editor Command

I am a new Linux and Unix user. How do I exit the VIM text editor on a Linux/Unix-like operating systems? How to exit Vim editor?

Vi or vim is a text editor for Linux and Unix-like operating systems. It can be used to edit all kinds of plain text files. It is especially useful for editing programs, scrpits or system configuration files located in /etc/ or /usr/local/etc/ directories.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Time1m
The basic syntax is as follows to open a file using vim:
vim filenmame
vi filename
vim [options] filename

ADVERTISEMENTS

How to exit VIM text editor

The procedure is as follows to quit vim/vi text editor:

  1. First, you need to switch to command mode. This can be done by hitting the Esc key. Next, you can type the following commands:
  2. :q to quit.
  3. :q! to quit without saving data/file.
  4. :x save and quit.
  5. :qa to quit all open files.
  6. Please note that whenever you type :, a vim or vi : will appear at the bottom of the screen. You need to type the rest of the command at the bottom of the screen.

How to exit the Vim editor without saving
Let us see some examples and method to exit from vim session.

How to exit vim editor in terminal (method #1)

  1. Press the Esc key
  2. Type :
  3. Next, type q
  4. Hit the Enter key

vim: How do I quit from Vi (method #2)?

  1. You can press the Esc key.
  2. Type SHIFT Z Z to save and exit.
    OR
    Type SHIFT Z Q to exit without saving.

Related media (Video) – Exit from the vim/vi text editor command

This tutorial is also available in a quick video format:

 


(Video 01: How to exit from the vim/vi text editor)

 

How to learn vim

Use vimtutor command. It starts the Vim tutor. The Vimtutor is useful for new Linux or Unix sysadmin or developers who want to learn their first Vim commands. By default, vimtutor starts in English or the language of the current locale will be used:
$ vimtutor
To start in other languages add language parameter as follows:
$ vimtutor it ## Italian ##
$ vimtutor es ## Spanish ##
$ vimtutor fr ## French ##

To see all installed languages run the following ls command:
$ ls /usr/share/vim/vim*/tutor/tutor*

Conclusion

You learned how to exit vim text editor using various options. See vim docs here for more info.

This entry is 2 of 4 in the Exit From Linux and Unix "app" Tutorial series. Keep reading the rest of the series:
  1. How To Exit From top Command In Linux / Unix / BSD / OS X
  2. How To Exit Vim Text Editor Command
  3. Vi / Vim: Save And Quit The Editor Command
  4. How to reload .vimrc file without restarting vim on Linux/Unix
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
8 comments… add one
  • aref ghobadi Aug 17, 2015 @ 9:50

    Hi
    thanks

  • suyash Nov 9, 2015 @ 7:27

    simple :)

    • yahza Dec 9, 2015 @ 14:09

      doesn’t seem to b working

  • Red Panda Apr 24, 2016 @ 20:48

    I love you man thanks for this I searched loads of places and this was the clearest

  • Spiros M. Jun 29, 2016 @ 16:01

    When I’m pissed of with something I’m like: Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc Esc :Q!

    And then the angrer level goes to the sky for pressing capital Q instead of the lowercase one…

  • Emmanuel Aug 4, 2016 @ 18:39

    Thanks. Pretty clear and straight to the point.

  • Ritesh Feb 7, 2017 @ 11:22

    Thanks for posting, very clear!

  • didi May 23, 2017 @ 18:49

    Type Esc:help and you will have all help and even a neat tutorial:
    :help
    To start the Vim tutor, type the following at shell prompt:
    $ vimtutor

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.