How to exit the Vim editor when :q or :x doesn't work
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
- Esp Z + Z
- :wq!
fletch
Updated on June 05, 2022Comments
-
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 over 6 years
:qa!
will quit an unlimited number of buffers regardless of their saved-ness -
Jeff Richards over 6 yearsDon't forget to exit edit mode by pressing escape. For the truly new, it's possible to get stuck in edit mode.