How To Exit Vim Text Editor Command

See all VI / Vim text editor related FAQs/HowTos
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
Difficulty level Easy
Root privileges No
Requirements Linux or Unix terminal
Category Text Editor
Prerequisites vim or vi
OS compatibility AIX AlmaLinux Alpine Arch BSD Debian Fedora FreeBSD HP-UX Linux macOS Mint NetBSD OpenBSD openSUSE Pop!_OS RHEL Rocky Stream SUSE Ubuntu Unix WSL
Est. reading time 2 minutes
The basic syntax is as follows to open a file using vim:
$ vim filenmame
$ vi filename
$ vim [options] filename

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.
    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 will start the Vim tutor from the CLI. The Vimtutor is useful for new Linux or Unix sysadmins, users 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. For example:
$ 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*
$ ls -l /usr/share/vim/vim*/tutor/tutor*

-rw-r--r-- 1 root root 33257 May 24 19:58 /usr/share/vim/vim81/tutor/tutor
-rw-r--r-- 1 root root 40896 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 41845 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 60525 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 28437 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 28917 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 25677 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.cs
-rw-r--r-- 1 root root 36195 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 53562 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 33257 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.utf-8
-rw-r--r-- 1 root root  5461 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.vim
-rw-r--r-- 1 root root 32339 May 24 19:58 /usr/share/vim/vim81/tutor/
-rw-r--r-- 1 root root 24364 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.zh.big5
-rw-r--r-- 1 root root 38811 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.zh_cn.utf-8
-rw-r--r-- 1 root root 30043 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.zh.euc
-rw-r--r-- 1 root root 31408 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.zh_tw.utf-8
-rw-r--r-- 1 root root 31408 May 24 19:58 /usr/share/vim/vim81/tutor/tutor.zh.utf-8


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

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

13 comments… add one
  • Anonymous Feb 2, 2024 @ 15:02

    Alright, listen up, you butterfingered newbie! Stuck in the clutches of Vim again, are you? Don’t worry, I ain’t got all day, so I’ll tell you this once:

    Wanna save your mess and escape? Slam your grubby fingers on :wq and be done with it. But if you haven’t saved and wanna ditch like a digital rat, :q!, you hear? Don’t even think about crying about lost work, that’s your fault for not saving like a responsible human.

    Multiple files got you tied down? :qa! will nuke ’em all, no questions asked. Just remember, once you hit enter, it’s gone forever, faster than your dreams of coding mastery.

    Now get outta here before I unleash the wrath of the command line on you! And for the love of all that is holy, learn the modes next time. I won’t be so gentle then!

  • deep hazra Apr 20, 2024 @ 7:27

    Thanks for sharing these Linux commands with us.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.