vi exit write mode - CoursesEssaydatesCom

vi exit write mode

Skip to content


Linux and Unix tutorials for new and seasoned sysadmin


Linux and Unix tutorials for new and seasoned sysadmin


Vi / Vim: Save And Quit The Editor Command

last updated in Categories Linux , UNIX , Vim

I am a new vi (vim) text editor user. How do I quit the vi editor and save my changes under a Linux or Unix like operating systems?

vi or vim (Vi IMproved) is text editor or a programmers text editor. You can edit programs or configuration files on the Linux/Unix server. Vim is upwards compatible to Vi. You can start vi/vim by typing the following command:
vim file
vi file
vim [options] filename

How to save and quit the vi or vim text editor

To save and quit the vi or vim editor with saving any changes you have made:

  1. If you are currently in insert or append mode, press Esc key.
  2. Press : (colon). The cursor should reappear at the lower left corner of the screen beside a colon prompt.
  3. Enter the following command (type 😡 and press Enter key):




  4. Press ENTER key
  5. This will quit the editor, and all changes you have made to the document will be saved to the file.

Use x to save a file and exit:

Fig.01: Vi / vim save and quit demo.
Fig.01: Vi / vim save and quit demo.

How to trash all changes in vi/vim

If you do not want to save any changes, first press Esc key. To exit Vim without saving changes press :q! followed by ENTER key.

Getting more help about vim commands

Want to learn vim text editor? Start the vim tutor by typing the following command at the Linux, macOS, and Unix-like system:
$ vimtutor
$ vimtutor it
$ vimtutor fr

Summary of vim/vi commands

Press the ESC key
Type :q!
Press the ENTER key
Exit vim without saving changes i.e. discards any changes you made.
Press the ESC key
Type :wq
Press the ENTER key
Save a file and exit.
Press the ESC key
Type 😡
Press the ENTER key
Save a file and exit.
This entry is 3 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

Posted by: Vivek Gite

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 .

Your support makes a big difference:

I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft takes a lot of my time and hard work to produce. If everyone who reads nixCraft, who likes it, helps fund it, my future would be more secure. You can donate as little as $1 to support nixCraft:

Become a Supporter Make a contribution via Paypal/Bitcoin

Related tutorials and howtos

  • Vi / Vim Quit Without Saving Command
  • How To Exit Vim Text Editor Command
  • HowTo: Save File in Vi / Vim Text Editor
  • How to create a new file with vim
  • How to reload .vimrc file without restarting vim on Linux/Unix

10 comment

  1. Hi,

    w!= save without exiting
    q!= exit without saving

  2. To save and quit:
    If you are currently in insert or append mode, press Esc key.
    Press: (semi-colon) The cursor should reappear at the lower left corner of the screen beside a colon prompt.
    Enter the following command (type wq! and press Enter key).

    1. Press: (colon) The cursor should reappear at the lower left corner of the screen beside a colon prompt.
      colon is right.

  3. none of these commands are working

    1. Hit the ‘esc’ key and it will take you out of the cursor mode and give you a cursor at the lower left hand of the screen. Now enter wq! and it will save and quit.

  4. Worked for me (Ubuntu 16.4). Thanks

  5. Thanks for sharing knowledge!
    Worked just perfectly!

  6. worked for me too on Ubuntu. thank you!

  7. The theme become so popular in the entire Www, so I’ve created fun page

    1. Can’t believe I clicked your link 🙂

    Have a question? Post it on our forum!

Tagged as: Tags CentOS , debian , fedora , FreeBSD , Openbsd , rhel , ubuntu , vim :x! , Easy

Featured Articles:

Related Posts:

Sign up for my newsletter

RSS Recently updated

Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

  1. Log In
    Sign Up

This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service .
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct .

Unix & Linux

Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up

Here’s how it works:

Anybody can ask a question

Anybody can answer

The best answers are voted up and rise to the top

How do I quit from Vi?

Ask Question

up vote
down vote



I started Vi on my Ubuntu machine. However I’m new to Vi, and now I can not quit. I see the editor and I can write text, at the bottom line there is a label “recording”.

How do I quit Vi?

vim keyboard-shortcuts editors
share | improve this question

edited Jun 23 ’16 at 10:23



asked Oct 20 ’10 at 22:40



  • 1

    The "recording" by the way meant that you were recording a macro. Not that that matters any more.
    –  frabjous
    Oct 20 ’10 at 23:19

  • 4

    This question brings back such "fun" memories. I’m so glad I got over that feeling, however.
    –  frabjous
    Oct 21 ’10 at 1:06

  • How we can come back in insert mode from read only mode in Linux (Ubuntu in VMware installed ) VI Editor?
    – user81572
    Aug 21 ’14 at 17:39

  • 2

    Quitting Vim has become a meme now.
    –  noɥʇʎԀʎzɐɹƆ
    Jun 23 ’16 at 22:59

  • 1

    For those who haven’t seen that joke yet:
    –  Federico Poloni
    Dec 13 ’16 at 8:53

show 1 more comment

6 Answers




up vote
down vote


vim is a modal editor . Hit the ESC key to get into Normal (command) mode then type :q and press Enter.

To quit without saving any changes, type :q! and press Enter.

See also Getting out in Vim documentation.

share | improve this answer

answered Oct 20 ’10 at 22:47

Sinan Ünür


  • 9

    Thanks: I tried that commands, but after running them I was prompted with: E37: No write since last change (add ! to override). I have nothing to save.
    –  Jonas
    Oct 20 ’10 at 22:49

  • 10

    Use :wq if you want to save what you have edited and then exit. :q! if you want to exit and leave your changes behind.
    –  Steven D
    Oct 20 ’10 at 22:50

  • Or if you’ve written something you want to make a copy of, :w newFileName.txt, then sort out the read-only issue outside of vi or vim.
    –  Kevin Cantu
    Oct 20 ’10 at 23:17

  • 4

    quit :q ; force quit :q! ; quit and save :wq or :x
    –  fromnaboo
    Oct 6 ’12 at 10:52

  • 2

    @Jonas, next time try :qall!, I suspect you have open more files within one single buffer.
    –  Alan Dong
    Oct 4 ’15 at 4:03

show 1 more comment

up vote
down vote

I use ctrl+[ to generate the esc sequence, this keeps me from having to move my fingers from the home row (remember the esc key was in a different place when vi was invented. :wq will write all files regardeless of necessity. I suggest using ZZ (which is shift+z twice) which will only write if a change has been made in the file. Also :xa is the same as ZZ except if you have more than 1 file open in the editor instance (such as vim tabs). note: I’m not sure all this is 100% compat with all vi clones, but I know it works with vim

share | improve this answer

answered Oct 20 ’10 at 23:25



  • 1

    Thanks. The ZZ command seems to be useful. I can see the point with Ctrl+[ but I’m using a swedish keyboard layout and I have to press AltGr+8 to get [ so that would be Ctrl+AltGr+8 for me 🙁
    –  Jonas
    Oct 21 ’10 at 1:17

  • Also note ZQ is effectively the same as :q!. However, this is not standard. ZZ, on the other hand, is specified in POSIX .
    –  Wildcard
    Nov 18 ’16 at 1:59

add a comment  | 

up vote
down vote

The quit from the vi is another way is
Esc 😡.

The option is used for save and quit at the
same time.

share | improve this answer

edited Oct 6 ’12 at 15:27



answered Oct 6 ’12 at 10:45



  • 2

    Note that like ZZ, :x will write the file only if its content has changed, unlike :wq.
    –  jlliagre
    Nov 18 ’16 at 1:55

add a comment  | 

up vote
down vote

As Sinan said, vim is a modal editor. If you want to know whether that works for you you should maybe invest some time and run vimtutor which is an interactive way to learn vim. (It also covers how to exit, what the modes mean and what you can do in each mode).

share | improve this answer

answered Oct 20 ’10 at 22:53



add a comment  | 

up vote
down vote

After modification, please press ESC and the given command :wq!.

This will forcefully write the new modification on the read-only file. Earlier it was not working because the file is read-only.

share | improve this answer

edited Nov 18 ’16 at 1:36



answered Nov 18 ’16 at 0:53

Arif A.


  • 1

    Why are you answering a question from 4 years ago, with basically a rehash of the top answer? It’s wrong anyway: this won’t force write a read-only file- it will try to write, might fail, and then will force quit without saving.
    –  Chris
    Nov 18 ’16 at 3:56

  • I tried with the previous comments and it was not working. I thought it would be useful to share what I have done. It is not important when the question was posted, but whether the solutions are applicable or not.
    –  Arif A.
    Nov 21 ’16 at 15:00

add a comment  | 

up vote
down vote

try combination of control and Z

share | improve this answer

edited Dec 13 ’16 at 8:55



answered Dec 13 ’16 at 8:44



  • 1

    This will keep vi in background;
    –  Archemar
    Dec 13 ’16 at 12:37

add a comment  | 

Not the answer you’re looking for? Browse other questions tagged vim keyboard-shortcuts editors or ask your own question .


7 years, 10 months ago


212,804 times


22 days ago



Spoofing or removing DHCP client hostname in response to DHCP server



How can I move to the bottom of a document using the pico editor?


Problem : how can I copy/paste this in vim?


In Gedit, how might I jump from the command line (bottom frame) to the file explorer frame to the text editor frame using keyboard shortcuts


Sudoedit Vim force write (update) without quit


Can I speed up pasting into vim?


In vim, how do you run a command silently in the background?


Move one screen row up/down in a multi-line text


Move in crontab -e editor


Text editor for printing C++ code


Copy grep output from vim editor

Hot Network Questions

  • What happens when a PC drops to 0 HP outside of combat?

  • Why don’t bond makers just get loans?

  • How would one attack or lay siege to a flying castle?

  • Are there examples of conjectures supported by heuristic arguments that have been finally disproved?

  • SQL Server: can dynamic data masking be safe when providing a database backup?

  • How useful is an impregnable castle?

  • QGIS: Delete all records/rows with NULL values

  • Custom Number Base Converter

  • accommodate the length of a string value to prevent STRING_TOO_LONG issue

  • S and P 500 Prediction

  • Would a glass sword be plausible and useful?

  • Is Moon pinging by laser which was shown in the ‘Big Bang Theory’ possible?

  • What is the term used for the opposite of a construct form?

  • NPE with initialized variable

  • Detect 220 VAC with a Raspberry Pi

  • Change of font in my moderncv CV

  • Why did I have to wave my hand in front of my ID card?

  • \text vs \scalebox

  • How to Write an Eldritch Abomination?

  • Who’s not welcome here?

  • How can I make my girlfriend not to get fixated on false facts and listen for reasons?

  • How to ask my employer if a training course I took a while back has a clause attached to it ("stay at x employer for n months")?

  • How can I help a close friend get over me?

  • Why do airliners have to park so accurately?

more hot questions

question feed

Unix & Linux Stack Exchange works best with JavaScript enabled