How to exit the Vim editor when :q or :x doesn't work

10,705

Solution 1

:q should work, unless the file hasn't been saved.

:q! will work.

:wq will attempt to save and quit, but won't quit if it can't save.

:wq! will attempt to save, and then quit whether or not it can save.

E: Credit to @GregoryNisbet for reminding me: if you have multiple files open, there is a series of 'all' quit commands:

:qa should quit all buffers (open files, more or less).

:qa! will quit all buffers regardless of if they have been saved.

:wqa will attempt to save and quit all buffers.

:wqa! will attempt to save all buffers, and then quit whether or not they are saved.

Solution 2

The solution that has worked for me is

  1. Esp Z + Z
  2. :wq!
Share:
10,705
fletch
Author by

fletch

Updated on June 05, 2022

Comments

  • fletch
    fletch almost 2 years

    Newbie to vi / vim, I normally use pico but using a locked down box (for now) that only has these 2 editors.

    I am having trouble getting it to save a file or even just quit. I see others having the same issue and they were told to use :x but even that doesn't work, just throws up an error message.

    Is there an exit command that JUST works?

    thanks

  • Greg Nisbet
    Greg Nisbet over 6 years
    :qa! will quit an unlimited number of buffers regardless of their saved-ness
  • Jeff Richards
    Jeff Richards over 6 years
    Don't forget to exit edit mode by pressing escape. For the truly new, it's possible to get stuck in edit mode.